supremainc / BioStar2_device_SDK

36 stars 25 forks source link

BS2_UpgradeFirmware function not working on linux #28

Open blaze124 opened 1 year ago

blaze124 commented 1 year ago

We are developing a console application in .net 7 which can be executed in windows and linux environments for managing devices.

One of our desired functionalities is upgrading the firmware using an API endpoint.

In windows we have no problems and everything runs fine, but when we execute our app in linux we get this error:

_symbol lookup error: /my_folder/libBS_SDK_V2.dll.so: undefined symbol: BIO_new_membuf

It happens when we make this call:

result = (BS2ErrorCode)API.BS2_UpgradeFirmware(GlobalValues.sdkContext, (uint)deviceId, fwData, fwDataLen, 0, null!);

The whole function, is this:

`public int UpgradeFirmware(int deviceId) { BS2SimpleDeviceInfo info = Util.AllocateStructure();

        BS2SimpleDeviceInfoEx infoEx = Util.AllocateStructure<BS2SimpleDeviceInfoEx>();

        BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetDeviceInfoEx(GlobalValues.sdkContext, (uint)deviceId, out info, out infoEx);

        if (result == BS2ErrorCode.BS_SDK_SUCCESS)
        {
            string firmware = "../firmware/";
            string file = "";

            if (info.type == (ushort)BS2DeviceTypeEnum.BIOSTATION_A2)
            {
                //file = "bsa2-ompw_v1.9.1_20220113_sign.bin";
                file = "bsa2-ompw_v*_sign.bin";
            }
            else if (info.type == (ushort)BS2DeviceTypeEnum.FACESTATION_2)
            {
                //file = "fs2_d_v1.5.3_20221103_sign.bin";
                file = "fs2_d_v*_sign.bin";
            }
            else if (info.type == (ushort)BS2DeviceTypeEnum.FACESTATION_F2 || info.type == (ushort)BS2DeviceTypeEnum.FACESTATION_F2_FP)
            {
                //file = "fstf2-all_v2.1.3_20230525_sign.bin";
                file = "fstf2-all_v*_sign.bin";
            }
            else
                return -2; //Tipo de dispositivo no contemplado

            string[] files = Directory.GetFiles(firmware, file);

            if (files.Length == 0)
                return -3; //No se ha encontrado el fichero de firmware

            string lastFile = files.OrderDescending().First();

            IntPtr fwData = IntPtr.Zero;
            uint fwDataLen = 0;

            if (Util.LoadBinary(lastFile, out fwData, out fwDataLen))
            {
                result = (BS2ErrorCode)API.BS2_UpgradeFirmware(GlobalValues.sdkContext, (uint)deviceId, fwData, fwDataLen, 0, null!);
                Marshal.FreeHGlobal(fwData);

                if (result == BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    return 1;
                }
                else
                    return -5; //Ha fallado el proceso de upgrade
            }
            else
                return -4; //No ha podido cargar el binario del firmware
        }

        return -1; //No se ha podido obtener la informacion del dispositivo
    }`
Pau-Serra commented 1 year ago

Even with the latest 2.9.4.0 version, in Ubuntu 22.04 you have to use the LD_PRELOAD trick

With SDK prior to 2.9.4.0 in Ubuntu 20.04:

LD_PRELOAD=/usr/lib/x8664-linux-gnu/libcrypto.so.1.1 ./yourLinuxApp_

With SDK 2.9.4.0 in Ubuntu 22.04:

LD_PRELOAD=/usr/lib/x8664-linux-gnu/libcrypto.so.3 ./yourLinuxApp_