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!
  3. Original Question
  4. -----------------
  5. Edit: **I figured out that I could flash firmware for F@ST 2704N from [][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.**
  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.
  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.
  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.
  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'".
  16. CPU Info:
  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
  35.     unaligned exceptions            : 112
  37. Linux Version:
  39.     # cat /proc/version
  40.     cat /proc/version
  41.     Linux version 2.6.30 ( (gcc version 4.4.2 (Buildroot 2010.02-git) ) #1 Fri Jun 1 15:13:39 CST 2018
  44. File Analysis:
  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/, corrupted section header size
  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
  72. My Hello World program:
  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
  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
  99. Example of trying to run hello world:
  101.      > sh
  102.     sh
  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.
  108.     # cd /tmp/
  109.     cd /tmp/
  110.     # nc 8081 > hello
  111.     nc 8081 > hello
  112.     # chmod +x ./hello
  113.     chmod +x ./hello
  114.     # ./hello
  115.     Killed
  118.   [1]:
  119.   [2]:
  120.   [3]:
  123. --------
  124. I should mention, the reason I am not compiling OpenWRT for it's binaries is because my [specific chip]( is not supported by OpenWRT and I already ran make menuconfig per [these instructions]( and I don't see my chip in the list of supported systems. – SenorContento Jan 22 at 18:18
  126. Nevermind on not trying to compile for OpenWRT. I decided to read further on the [OpenWRT Wiki]( 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
  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
  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
  132. Could you compile it statically? Maybe so it won't die on the spot. Reopen vote given. – peterh yesterday (Jan 26, 2019)
  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)
  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/" as an interpreter. I copied, 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