Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://unix.stackexchange.com/questions/496003/how-to-compile-against-uclib-interpreter-for-mips-gcc
- Original Question
- -----------------
- Edit: **I figured out that I could flash firmware for F@ST 2704N from [OpenWRT.org][1]. I used the link with the luci web interface and I now have OpenWRT on my router. This question is still valid because I would like to learn how to cross compile programs for my router, but now it should be easier since I am not trying to work against the builtin firmware.**
- I have and old [Safemcom Fast 1704N router][2] that I want to replace the system with my own custom linux installation. I want to cross compile dd for the router so I can back up the current system before I proceed to figure out how to install a new system on it. Currently I am trying to compile a simple hello world program using the tutorial I found at [The Airport Wiki][3]. I am running gcc on a Macbook Air and I have replaced the air's sed with GNU's sed (important to compile last stage compiler). I know the router uses Mips32 version 1 because I copied a version of netcat and the uClib library I found on the router over to my computer and I inspected it.
- I currently do not know how to link to the interpreter that the router has and trying to run the example hello world program found in The Airport Wiki tutorial just results in the message "Killed". I use netcat to transfer the binary over to the router and back on ethernet.
- Lastly, I should mention, I did somewhat ignore the versions of the compiler tools for the tutorial and decided to use the latest versions of the tools I found by poking around on the sites linked in the The Airport Wiki tutorial.
- ### Edit:
- My question is, "How do I compile a program for the Mips32 version 1 processor that is on the Safemcom Fast 1704N router? The program I currently have compiled just results in 'Killed' instead of saying 'Hello Mips'".
- CPU Info:
- # cat /proc/cpuinfo
- cat /proc/cpuinfo
- system type : F@ST1704N
- processor : 0
- cpu model : Broadcom BCM3302 V3.3
- BogoMIPS : 331.77
- wait instruction : yes
- microsecond timers : yes
- tlb_entries : 32
- extra interrupt vector : no
- hardware watchpoint : no
- ASEs implemented :
- shadow register sets : 1
- core : 0
- VCED exceptions : not available
- VCEI exceptions : not available
- unaligned exceptions : 112
- Linux Version:
- # cat /proc/version
- cat /proc/version
- Linux version 2.6.30 (jenkins@sz01017.ads.local) (gcc version 4.4.2 (Buildroot 2010.02-git) ) #1 Fri Jun 1 15:13:39 CST 2018
- File Analysis:
- Alexs-MacBook-Air:Processor-Info senor$ file nc
- nc: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, corrupted section header size
- Alexs-MacBook-Air:Processor-Info senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h nc
- ELF Header:
- Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
- Class: ELF32
- Data: 2's complement, big endian
- Version: 1 (current)
- OS/ABI: UNIX - System V
- ABI Version: 0
- Type: EXEC (Executable file)
- Machine: MIPS R3000
- Version: 0x1
- Entry point address: 0x4043b0
- Start of program headers: 52 (bytes into file)
- Start of section headers: 0 (bytes into file)
- Flags: 0x50001007, noreorder, pic, cpic, o32, mips32
- Size of this header: 52 (bytes)
- Size of program headers: 32 (bytes)
- Number of program headers: 7
- Size of section headers: 0 (bytes)
- Number of section headers: 0
- Section header string table index: 0
- My Hello World program:
- Alexs-Air:hello-world senor$ file hello
- hello: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with debug_info, not stripped
- Alexs-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h hello
- ELF Header:
- Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
- Class: ELF32
- Data: 2's complement, big endian
- Version: 1 (current)
- OS/ABI: UNIX - System V
- ABI Version: 0
- Type: EXEC (Executable file)
- Machine: MIPS R3000
- Version: 0x1
- Entry point address: 0xa0020004
- Start of program headers: 52 (bytes into file)
- Start of section headers: 200884 (bytes into file)
- Flags: 0x50001001, noreorder, o32, mips32
- Size of this header: 52 (bytes)
- Size of program headers: 32 (bytes)
- Number of program headers: 2
- Size of section headers: 40 (bytes)
- Number of section headers: 29
- Section header string table index: 28
- Example of trying to run hello world:
- > sh
- sh
- BusyBox v1.17.2 (2018-06-01 15:16:56 CST) built-in shell (ash)
- Enter 'help' for a list of built-in commands.
- # cd /tmp/
- cd /tmp/
- # nc 192.168.254.1 8081 > hello
- nc 192.168.254.1 8081 > hello
- # chmod +x ./hello
- chmod +x ./hello
- # ./hello
- Killed
- [1]: https://webcache.googleusercontent.com/search?q=cache:SowpqcVxHOYJ:https://openwrt.org/toh/plusnet/fast2704nv1%20&cd=1&hl=en&ct=clnk&gl=us
- [2]: http://www.sagemcom.com/broadband/gateways/dsl-gateways/fst-1704n-2704n/
- [3]: http://www.theairportwiki.com/index.php?title=Building_a_cross_compile_of_GCC_for_MIPS_on_OS_X
- Comments
- --------
- I should mention, the reason I am not compiling OpenWRT for it's binaries is because my [specific chip](https://openwrt.org/docs/techref/hardware/soc/soc.broadcom.bcm33xx?s%5B%5D=bcm3302) is not supported by OpenWRT and I already ran make menuconfig per [these instructions](https://medium.com/@jam3s/finding-command-injections-on-a-router-using-strace-16dfc2e8648b) and I don't see my chip in the list of supported systems. – SenorContento Jan 22 at 18:18
- Nevermind on not trying to compile for OpenWRT. I decided to read further on the [OpenWRT Wiki](https://openwrt.org/docs/techref/hardware/soc/soc.broadcom.bcm33xx?s%5B%5D=bcm3302) and found `This chip seems to be a general-purpose MIPS CPU. It is usually included with other platforms like bcm47xx and such.` I am going to try to compile for the bcm47xx architecture. – SenorContento Jan 22 at 18:29
- I've got to the bottom of your question and I'm still not sure what it is you're actually asking. – roaima Jan 22 at 21:52
- I am trying to compile a program for the F@ST1704N router. I am currently working on a hello world program to just get things started, but I am having trouble getting the hello world program to run. – SenorContento Jan 22 at 22:17
- Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given. – peterh yesterday (Jan 26, 2019)
- I can compile it statically. It's the binary I am having trouble with. The command I tried to use to emulate the same settings as netcat is "mips-netbsd-elf-gcc -mips32 -Tidt.ld hello.c -o hello". Using "mips-netbsd-elf-gcc -mips32 -Tidt.ld -static hello.c -o hello" produces the same binary. I compared the hex values. I modified the compile command from the Airport Wiki tutorial. – SenorContento yesterday (Jan 26, 2019)
- I think my problem is that I don't have an interpreter linked. Netcat and other binaries already on the router link to "/lib/ld-uClibc.so.0" as an interpreter. I copied ld-uClibc.so.0, but I cannot figure out how to link it. I tried linking it as a library, but that doesn't work and I cannot figure out what option(s) I need to set to link the file as an interpreter. The only other thing different AFAIK is that the onboard binaries have corrupted headers, but I think that was just to save space on the router. Imaging the router gives me a ~5 MB binary, so there isn't much space for headers. – SenorContento yesterday (Jan 26, 2019)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement