SHARE
TWEET

Original Question about MIPS Compiling

SenorContento Jan 26th, 2019 1,239 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. https://unix.stackexchange.com/questions/496003/how-to-compile-against-uclib-interpreter-for-mips-gcc
  2.  
  3. Original Question
  4. -----------------
  5. 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.**
  6.  
  7. 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.
  8.  
  9. 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.
  10.  
  11. 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.
  12.  
  13. ### Edit:
  14. 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'".
  15.  
  16. CPU Info:
  17.  
  18.     # cat /proc/cpuinfo
  19.     cat /proc/cpuinfo
  20.     system type             : F@ST1704N
  21.     processor               : 0
  22.     cpu model               : Broadcom BCM3302 V3.3
  23.     BogoMIPS                : 331.77
  24.     wait instruction        : yes
  25.     microsecond timers      : yes
  26.     tlb_entries             : 32
  27.     extra interrupt vector  : no
  28.     hardware watchpoint     : no
  29.     ASEs implemented        :
  30.     shadow register sets    : 1
  31.     core                    : 0
  32.     VCED exceptions         : not available
  33.     VCEI exceptions         : not available
  34.    
  35.     unaligned exceptions            : 112
  36.    
  37. Linux Version:
  38.  
  39.     # cat /proc/version
  40.     cat /proc/version
  41.     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
  42.  
  43.  
  44. File Analysis:
  45.  
  46.     Alexs-MacBook-Air:Processor-Info senor$ file nc
  47.     nc: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, corrupted section header size
  48.    
  49.    
  50.     Alexs-MacBook-Air:Processor-Info senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h nc
  51.     ELF Header:
  52.       Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  53.       Class:                             ELF32
  54.       Data:                              2's complement, big endian
  55.       Version:                           1 (current)
  56.       OS/ABI:                            UNIX - System V
  57.       ABI Version:                       0
  58.       Type:                              EXEC (Executable file)
  59.       Machine:                           MIPS R3000
  60.       Version:                           0x1
  61.       Entry point address:               0x4043b0
  62.       Start of program headers:          52 (bytes into file)
  63.       Start of section headers:          0 (bytes into file)
  64.       Flags:                             0x50001007, noreorder, pic, cpic, o32, mips32
  65.       Size of this header:               52 (bytes)
  66.       Size of program headers:           32 (bytes)
  67.       Number of program headers:         7
  68.       Size of section headers:           0 (bytes)
  69.       Number of section headers:         0
  70.       Section header string table index: 0
  71.  
  72. My Hello World program:
  73.  
  74.     Alexs-Air:hello-world senor$ file hello
  75.     hello: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, with debug_info, not stripped
  76.    
  77.     Alexs-Air:hello-world senor$ /opt/cross/gcc-mips/bin/mips-netbsd-elf-readelf -h hello
  78.     ELF Header:
  79.       Magic:   7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00
  80.       Class:                             ELF32
  81.       Data:                              2's complement, big endian
  82.       Version:                           1 (current)
  83.       OS/ABI:                            UNIX - System V
  84.       ABI Version:                       0
  85.       Type:                              EXEC (Executable file)
  86.       Machine:                           MIPS R3000
  87.       Version:                           0x1
  88.       Entry point address:               0xa0020004
  89.       Start of program headers:          52 (bytes into file)
  90.       Start of section headers:          200884 (bytes into file)
  91.       Flags:                             0x50001001, noreorder, o32, mips32
  92.       Size of this header:               52 (bytes)
  93.       Size of program headers:           32 (bytes)
  94.       Number of program headers:         2
  95.       Size of section headers:           40 (bytes)
  96.       Number of section headers:         29
  97.       Section header string table index: 28
  98.  
  99. Example of trying to run hello world:
  100.  
  101.      > sh
  102.     sh
  103.    
  104.    
  105.     BusyBox v1.17.2 (2018-06-01 15:16:56 CST) built-in shell (ash)
  106.     Enter 'help' for a list of built-in commands.
  107.    
  108.     # cd /tmp/
  109.     cd /tmp/
  110.     # nc 192.168.254.1 8081 > hello
  111.     nc 192.168.254.1 8081 > hello
  112.     # chmod +x ./hello
  113.     chmod +x ./hello
  114.     # ./hello
  115.     Killed
  116.  
  117.  
  118.   [1]: https://webcache.googleusercontent.com/search?q=cache:SowpqcVxHOYJ:https://openwrt.org/toh/plusnet/fast2704nv1%20&cd=1&hl=en&ct=clnk&gl=us
  119.   [2]: http://www.sagemcom.com/broadband/gateways/dsl-gateways/fst-1704n-2704n/
  120.   [3]: http://www.theairportwiki.com/index.php?title=Building_a_cross_compile_of_GCC_for_MIPS_on_OS_X
  121.  
  122. Comments
  123. --------
  124. 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
  125.  
  126. 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
  127.  
  128. 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
  129.  
  130. 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
  131.  
  132. Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given. – peterh yesterday (Jan 26, 2019)
  133.  
  134. 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)
  135.  
  136. 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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top