Script: Convert device information to YAML

Hi all, based on this openwrt-devel mail thread I started a little script scraping some device specific information. This should eventually help creating and maintaining a device wiki with hardware information.

The output should be some YAML file which is then rendered into a fancy website.

I just figured out a few properties, I'd appreciate if somebody else could join in!

source /etc/os-release

#flash:
#  - size_mb: 128
#    type: SPI-NAND (Macronix)
#  - size_mb: 4
#    type: SPI-NOR (Macronix MX25R3235F)
#usb:
#  - version: 2
#    ports: 1
#  - version: 3
#    ports: 2
#ethernet:
#  - mbit: 100
#    ports: 4
#  - mbit: 1000
#    ports: 1
#vendor: Foobar
#model: Lorem Ipsum
#variant: v4

echo "soc: \"$(cat /proc/cpuinfo | grep 'system type' | cut -d ":" -f2 | sort | uniq | xargs)\""
echo "ram_mb: $(($(cat /proc/meminfo | grep MemTotal | xargs | cut -d " " -f 2) / 1024))"
echo "arch: $OPENWRT_ARCH"
echo "target: $OPENWRT_BOARD"
echo "id: \"$(cat /tmp/sysinfo/board_name)\""
echo "leds:"
for led in $(ls /sys/devices/platform/leds/leds/); do
    echo "  - \"$led\""
done
3 Likes

Tracked this on the mailing list.
I like that idea.
However, I would suggest that we pick it up during the build.
This has the advantage that for every build the information is up to date.
Everything else will stop simming after a while!

I found a project in python that parses a dtb file

The needed value can then be written into a YAML file and after that could be pushed to the web.

A played a little bit and it is working as expected.

Hi, thanks for the quick response. Could you please add an example output?
I don't see it as a big problem that the information is not continuously updated, as a device hardware unlikely change over time. A TP-Link 4300 will always keep the same SoC and amount of memory.

@feckert ping?

Sorry for the delay I am just somewhere else at the moment. My boss is breathing down my neck :wink:

If I still have time today, I will put together a small script.
First of all, a question:
Since I am based on the python libaries fdt and yaml, is that a problem? I am thinking about the dependencies.
For testing python I always use pipenv. Is this an option in openwrt if we want to build this information during build? This is my pipfile

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
fdt = ""
pyyaml = "
"

[requires]
python_version = "3.7"

this one is hit and miss @aparcar... perhaps deriving from;

/etc/os-release >>>
OPENWRT_ARCH... |+ OPENWRT_BOARD

etc. etc. might be yield more frequent results... ( readelf? )

I'm fine with Python 3.7, however current master seem to use Python 3.8.1.

Hopefully the scripts wont get to complicated, so we can adapt this later.

I'll be mostly offline until Sunday, sorry for rushing and now being offline :roll_eyes:

Sorry I don't full understand your post.... can you please elaborate

[root@synology-001132 /]# cat /proc/cpuinfo | grep 'system type' | cut -d 
":" -f2 | sort | uniq | xargs

#versus
[root@synology-001132 /]# cat /etc/os-release | grep 'OPENWRT_ARCH=' | grep -q 'arm' && echo armlike
armlike ( not exactly but you get the picture, case or something else entirely et. al. )

the rest all ok here...

This script converts the device tree files (dtb) coming from the openwrt build into yml files.
So far only the model and the soc is written. I have tested only with the lantiq target.
The generated dtb files for this target are located in the directory <openwrt>/build_dir/target-mips_24kc_musl/linux-lantiq_xrx200

So i called my script from my pipenv directory with the following command line.
./device-info.py -i <openwrt>/build_dir/target-mips_24kc_musl/linux-lantiq_xrx200 -o ./info

And I got in the output directory the yml files for all dtb files in the input directory.

For example:

model: BT OpenReach VDSL Modem
soc: alphanetworks,asl56026

Perhaps we can continue working on this basis

Not to take anything away from the OP or fellow contribs, but I use and recommend

which is an ansible-driven configuration collector ("gather facts") and can output to csv json markdown sql html or plain txt. The results are printed in a nice html clickable page for all hosts in your inventory file. Seems to work with openwrt, but not perfectly. ( I dont have pip3/python3 running yet).

Maybe this can give you ideas or combine bits of code to give you something even more Deluxe. Good luck yaml'ing and such.

Looks good to me, however we still have the problem that some values are auto detected... I guess a combination of both is the only way...

Thank you the tool looks good. However Python is a bit of a big package so I'd rather not have it as a dependency for the initial device info. Can you evaluate how well it works without Python on OpenWrt devices?

Where do we go from here?
If we want to automate the whole thing, then I think it's best to get the data from the devicetree binary blob with this script, since this is automatable during the build or doring a postprocess step.
Which information do we need from a running system?

Let's try to get all the data from the initial mail thread via device tree. Once done we can look for additional things scraped during run time