MEN-Mikro-Elektronik / 13MD05-90

MDIS5 System Package for Linux (including drivers)
Other
4 stars 4 forks source link

Possible `scan_system.sh` error #288

Closed duagon-rvw closed 1 year ago

duagon-rvw commented 1 year ago

There is a possibility for scan_system.sh to error out in line 568 (The line is identical on mad-dev):

//opt/menlinux/scan_system.sh: line 568: 16#: invalid integer constant (error token is "16#")

The line in Question:

        ipcoreId="$((16#${devid}))"

What the line is trying to do is to convert devid from base16 to base10. When devid is empty, this error occurs. You can reproduce this with bash like this: bash -c 'echo $((16#))'

Please check if this is already fixed.

Some more infos from the customer:

HW: We have 0701-0126 duadon device and placed F26L, F403 G227, G211X on it.

Scanning system. Calling /opt/menlinux/scan_system.sh /opt/menlinux --path=/home/ubuntu/13md05-90/13MD05-90
============================================================
MDIS System Scan - generate initial system.dsc / Makefile
============================================================

In case of warning: "Cannot use CONFIG_STACK_VALIDATION=y"
please install libelf-dev, libelf-devel or elfutils-libelf-devel

Backing up system.dsc
Scanning for MEN ID EEProm
Found CPU: F026. Using SMB address 12 for SMB2 based drivers
Building MDIS driver database..........done!
Scanning for MEN PCI devices:
Found possible MEN chameleon device(s), checking
Building IP core database..........................done!
//opt/menlinux/scan_system.sh: line 568: 16#: invalid integer constant (error token is "16#")
Finished
________________________________________________________________________________
Scan success

When looking at the code, I guess there is something going wrong with the parsing of the chameleon table.

mad-jsanjuan commented 1 year ago

Ok. So we have been seeing this error inconsistently when running our tests. The main issue is that the parsing of a chameleon table with scan_system.sh ends up always parsing an empty line. We thought the inconsistencies may come from different dumps of the chameleon tables read but it turns out the inconsistencies of the error come from different distributions when doing this 16#XX bash command. So in one distro, an empty value of devId in the expression ipcoreId="$((16#${devid}))" does not error and the others do:

It does not error when:

men@men-F027:/tmp$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
men@men-F027:/tmp$ echo $((16#FF))
255
men@men-F027:/tmp$ echo $((16#))
0

But it does error here:

men@men-a25:/tmp$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
men@men-a25:/tmp$ 
men@men-a25:/tmp$ echo $((16#FF))
255
men@men-a25:/tmp$ echo $((16#))
-bash: 16#: invalid integer constant (error token is "16#")

So we can just add a double check so that the script does not try to parse empty lines.