Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile under Linux (undefined reference to `main') #2

Open
isopix opened this issue Jan 16, 2021 · 19 comments
Open

Cannot compile under Linux (undefined reference to `main') #2

isopix opened this issue Jan 16, 2021 · 19 comments

Comments

@isopix
Copy link

isopix commented Jan 16, 2021

After typing command from Readme.md, I'm getting such error (I guess it's maybe supposed to be used only as library, right?

gcc -fPIC -Ofast Linux/AsmIOLinux.c -o libAsmIOLinux.so
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/10.2.1/../../../../lib/Scrt1.o: in function _start': (.text+0x24): undefined reference to main'
collect2: error: ld returned 1 exit status

BTW, I do wonder If I could use this tool to flash ASMT-1051, that has been unsuccesfully flashed by incorrect firmware (151030_B1_0B_01.bi from 105MPTools_v2.2.0.0.rar, that somebody posted as correct firmware for it on usbdev.ru)
I still got correct firmware that worked on it before, but ASMedia MPTool(or other windows tools) doesn't detect it now as ASMT-1051

I'm attaching lsusb and kernel logs, before I wrote any firmware to it:

174c:1153 ASMedia Technology Inc. ASM1153 SATA 3Gb/s bridge

[102714.433596] usb 3-1: new SuperSpeed Gen 1 USB device number 5 using xhci_hcd
[102714.446109] usb 3-1: New USB device found, idVendor=174c, idProduct=55aa, bcdDevice= 1.00
[102714.446114] usb 3-1: New USB device strings: Mfr=2, Product=3, SerialNumber=1
[102714.446117] usb 3-1: Product: ASMT1051
[102714.446119] usb 3-1: Manufacturer: asmedia
[102714.446120] usb 3-1: SerialNumber: 12345678BDFC
[103611.625111] usb 3-1: USB disconnect, device number 5
[103833.565577] usb 3-1: new SuperSpeed Gen 1 USB device number 6 using xhci_hcd
[103833.578355] usb 3-1: New USB device found, idVendor=174c, idProduct=1153, bcdDevice= 0.01
[103833.578358] usb 3-1: New USB device strings: Mfr=2, Product=3, SerialNumber=1
[103833.578360] usb 3-1: Product: AS2115
[103833.578361] usb 3-1: Manufacturer: ASMedia
[103833.578362] usb 3-1: SerialNumber: 00000000000000000000

@hartimcwildfly
Copy link
Contributor

hartimcwildfly commented Jan 22, 2021

The command is wrong. The correct one for linux is: gcc -shared -o libAsmIOLinux.so -fPIC Linux/AsmIOLinux.c
See PR #3

@isopix
Copy link
Author

isopix commented Jan 22, 2021

OK, it compiles now. But I stil do wonder how to compile "ASMTool" executable (mentioned below in README.md)? Or maybe this information is also incorrect and it's only library for now?

 Place the resulting .so file next to the ASMTool executable (obtained by building this project)

@hartimcwildfly
Copy link
Contributor

I didn't know either. I ported it to .NET 5 which is easier to handle on linux. See my forked project. I'm now able to build the project and the lib is loaded at the start. But the applications exits because of a memory fault. With this you only need to run dotnet build and place the libAsmIOLinux.so into folder ./bin/Debug/net5.0 then you can run ./bin/Debug/net5.0/AsmTool

@hartimcwildfly
Copy link
Contributor

Let me know if I could help you.

@hartimcwildfly
Copy link
Contributor

The project itself can be compiled under Linux with Jetbrains Rider, under Windows with Visual Studio or on both platform with the above mentioned dotnet build command when you have installed the .NET 5 SDK. The gcc command is only for compiling the linux specific library which is loaded by the AsmTool.

@hartimcwildfly
Copy link
Contributor

I analyzed the AsmIOLinux.c a little bit. It seems like the return values of the methods at initialization are not checked and thus the method call when reading fails with a segfault. I started to implement a more reliable version of this, but it's a lot of work. So at the moment better use the Windows version.

@isopix
Copy link
Author

isopix commented Jan 23, 2021 via email

@hartimcwildfly
Copy link
Contributor

Only the read functions are currently fully implemented. But it shouldn't be that hard to extend it with a write function. My main problem at the moment is the communication in general.

@smx-smx
Copy link
Owner

smx-smx commented Jan 30, 2021

Sorry, I didn't get notified about this issue and I missed the discussion.
Yes, it's supposed to be a shared library only and you need to run the dotnet binary as root.
Strange that it segfaults, I could give it another check on my machine

@smx-smx
Copy link
Owner

smx-smx commented Jan 30, 2021

As for the original issue, this tool was originally written for PCI based chips, not USB.
It surely won't work out of the box without writing ad-hoc USB code, and I don't have any ASMedia USB bridge chip with me at this time

@isopix
Copy link
Author

isopix commented Jan 30, 2021 via email

@smx-smx
Copy link
Owner

smx-smx commented Jan 30, 2021

I'm pretty sure i only have JMicrons, maybe one is USBest iirc

@ofl1
Copy link

ofl1 commented Mar 9, 2021

Hi @isopix
here is a version of the Linux file that compiles and works for me. I inserted the main and other necessary functions. With it I dumped the firmware of the ASM1042 in an ExpressCard. No other tool was able to do this. Before the compilation you have to enter the size of the firmware (64k/128k) and bus/device/function (from line 195). Remember: run as root, otherwise segfault.

Now the big question for everyone is: How can you expand it so that you can flash new firmware? Are there any ideas or research results?

AsmIOLinux.zip

@smx-smx
Copy link
Owner

smx-smx commented Mar 27, 2021

@ofl1 nice, thanks for sharing your version.
Is there any important change from the version in master besides the conversion to C-only?

Note that the linux backend was designed to be used from C#, that's why it's a shared library

As for writing the firmware, it's a matter of programming and testing the feature. I preferred to not do experiments back then as i wasn't sure if i risked bricking the controller

@ofl1
Copy link

ofl1 commented Mar 29, 2021

@smx-smx you are welcome. I didn't change anything on the old Linux backend, just added code. Omitted the controller's automatic search.

Your statements regarding writing the firmware sound like it is theoretically clear how to do it. There is great interest in such a possibility, because other tools do not work with certain ASM versions or SPI-ROMs.

My SPI-ROM was a P25D40H. I tried to expand your tool and experimented with SPIWrite without success. The content of the SPI-ROM was somehow overwritten, because when reading back afterwards only scrap arrived. Strangely, the controller still worked, just as good or bad as before. I also tried a programmer with clamp.

It is better to do the experiments with an ExpressCard than with chips on the mainboard, and to have a small supply of ExpressCards. For me, however, the issue has settled because I bought an ExpressCard with a different controller that works perfectly.

@smx-smx
Copy link
Owner

smx-smx commented Mar 31, 2021

As far as I know there is an unused part of the firmware (filled with zeros) which could be used to test the write functionality. If I get some spare time I could take a look

@isopix
Copy link
Author

isopix commented Mar 31, 2021 via email

@t0niX
Copy link

t0niX commented May 20, 2023

Hello all,

could somebody please help me out @hartimcwildfly, @smx-smx?

As I mistakenly flashed a wrong firmware to my ASM 3074 (I used one for an ASM 3142 as I thought that’s the chip on my motherboard; It still works though) I would like to re-flash the original firmware. Sadly it’s not available publicly

The good thing is: My motherboard has two ASM 3074 controllers of which one was deactivated during the flash so it still has the original firmware on it. This is the one I would like to dump the firmware from.

I am not a coder which is why I don’t have any tools to build myself a binary of your repo. Nevertheless I am trying my best and installed Visual Studio Code to build the version @hartimcwildfly provided. Anyways: It doesn't work because I don't have "libAsmIOLinux.so" available (I believe).

Would you be so kind to either compile a version for windows for me and share it or give me some support so I can build itr myself?

Can I re-flash the extracted firmware 1:1 or do I need to edit the file using a hex editor?

Thank you!!

@smx-smx
Copy link
Owner

smx-smx commented May 24, 2023

Would you be so kind to either compile a version for windows for me and share it or give me some support so I can build itr myself?

You can now download the latest build from Cirrus CI, as i just added build instructions with artifacts upload.
You can otherwise follow along https://github.com/smx-smx/ASMTool/blob/5bf8f1eb1041c7f4a6c79b952db8ab1143cab0de/.cirrus.yml to see how to replicate the build yourself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants