smx-smx / ASMTool

Firmware dumper and various utilities for ASMedia USB Controllers and related firmware
60 stars 10 forks source link

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

Open isopix opened 3 years ago

isopix commented 3 years ago

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 tomain' 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 commented 3 years ago

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

isopix commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Let me know if I could help you.

hartimcwildfly commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Thanks for all the help. BTW, do you know if I can use this tool to flash the chip if it's not opening the port, so official Windows software cannot see it? (I flashed bad firmware). Because otherwise it would be useless for me anyway.

On 1/23/21, Matthias Harter notifications@github.com wrote:

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.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/smx-smx/ASMTool/issues/2#issuecomment-765738658

hartimcwildfly commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Are you sure about not having one?

Most of "USB Sata cables/adapter" and usb SATA/mSATA enclosures got ASMedia chipset inside. Another thing if it's worth the effort ;-)

On 1/30/21, smx notifications@github.com wrote:

As about 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

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/smx-smx/ASMTool/issues/2#issuecomment-770195860

smx-smx commented 3 years ago

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

ofl1 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

That's super. As I've paid $2(SanDisk, open box) for this adapter, it's not a big loss (and will not be if it will get otally broken, because COM port doesn't work alrady).

But it would be huge win for owners of pricier adapter with similar chip.

but as I stated before, you can see it in device manager, but you cannot use it, nor flash another firmware(com port doesn't appear)

On 3/31/21, smx @.***> wrote:

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

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/smx-smx/ASMTool/issues/2#issuecomment-810991963

t0niX commented 1 year ago

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 commented 1 year ago

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