Advertisement
Guest User

setup-qemu-compiler-4-4-7-iz2s.sh

a guest
Apr 26th, 2015
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.06 KB | None | 0 0
  1. #!/bin/sh
  2. # How to get the brainfish IZ2S sd image running in qemu-user on mint-debian.
  3. # This is my take on the instructions provided here:  (I need it all spelled out)
  4. # http://brainfisheatfishbrain.com/2013/11/using-qemu-user-to-cross-compile-for-arm-on-ubuntu.html
  5.  
  6. # Do all this manually.  Do NOT run this as a script.  (maybe small pieces are ok)
  7.  
  8. # First install qemu
  9. #apt-get install qemu-user
  10. #apt-get install qemu-user-static
  11.  
  12. # And install some sort of chroot
  13. #apt-get install debootstrap
  14.  
  15.  
  16. # Check whether the binfmt entries were successfully registered:
  17. sudo update-binfmts --display
  18.  
  19. # Check for zipit Z2 in qemu support (should be last entry).
  20. qemu-system-arm -M ?
  21.  
  22. # Setup qemu for arm dev
  23. [ -d /proc/sys/fs/binfmt_misc ] || modprobe binfmt_misc
  24. [ -f /proc/sys/fs/binfmt_misc/register ] || mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  25.  
  26. # Register the arm handler:
  27. # su to root, then echo this to register
  28. #
  29. # Wait.  Do I really want to do this?  I think we can skip it.
  30. # (update-binfmts shows /usr/bin/qemu-arm-static as the interpretor for qemu-arm.
  31. #
  32. #sudo echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
  33.  
  34. # Create a chroot (./sd for example)
  35. # NOTE:  This should start out as an x86 chroot
  36. # with \bin\bash and all libs required by ldd /bin/bash
  37. # and with \bin\mount and all libs required by ldd /bin/mount
  38. # Then we replace it with an arm chroot after registering qemu in it.
  39.  
  40. mkdir sd/bin
  41. cp /bin/bash sd/bash
  42. mkdir -p sd/lib/i386-linux-gnu
  43. # Copy libs required by bash to sd/lib
  44. cp /lib/i386-linux-gnu/libncurses.so.5 sd/lib/i386-linux-gnu/
  45. cp /lib/i386-linux-gnu/libtingo.so.5 sd/lib/i386-linux-gnu/
  46. cp /lib/i386-linux-gnu/libtinfo.so.5 sd/lib/i386-linux-gnu/
  47. cp /lib/i386-linux-gnu/libdl.so.2 sd/lib/i386-linux-gnu/
  48. cp /lib/i386-linux-gnu/libc.so.6 sd/lib/i386-linux-gnu/
  49. cp /lib/ld-linux.so.2 sd/lib/
  50.  
  51. # Copy mount and libs required by mount to sd/lib
  52. cp /bin/mount sd/bin/
  53. cp /lib/i386-linux-gnu/libblkid.so.1 sd/lib/i386-linux-gnu/
  54. cp /lib/i386-linux-gnu/libselinux.so.1 sd/lib/i386-linux-gnu/
  55. cp /lib/i386-linux-gnu/libmount.so.1 sd/lib/i386-linux-gnu/
  56. cp /lib/i386-linux-gnu/libuuid.so.1 sd/lib/i386-linux-gnu/
  57. cp /lib/i386-linux-gnu/libpcre.so.3 sd/lib/i386-linux-gnu/
  58.  
  59. # Mount proc in the chroot;
  60. # Maybe use -o bind with mount to point my chroot proc at the real proc
  61. # That should be ok since I'm using chroot for qemu, not security purposes.
  62. #
  63. # cd sd
  64. # mkdir proc
  65. # mount -o bind /proc proc
  66. # cd ..
  67.  
  68. # Make proc and populate it.
  69. mkdir sd/proc
  70. mount -t proc sd/proc sd/proc
  71. sudo chroot sd
  72. # Setup qemu in the chroot.
  73. [ -f /proc/sys/fs/binfmt_misc/register ] || mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  74. # Exit the chroot
  75. exit
  76.  
  77. #Fetch the really nice IZ2S filesystem tgz from here:
  78. #http://brainfisheatfishbrain.com/2013/11/zipit-cross-compiling-real-life-apps-progress.html
  79. cd sd
  80. tar -xzvf ~/Downloads/iz2s_fat_buildenv_openmsxasm_291113.tgz
  81. cd ..
  82.  
  83. # Make an ls available (it's quite a challenge without ls).
  84. cd sd/bin
  85. ln -s busybox ls
  86. cd ../..
  87.  
  88. # The gcc-4.2.4 from the brainfish tarball is not quite built right for IZ2S.
  89. # So I don't recommend using it.  
  90. # Unfortunately it looks for the glibc dynamic linker instead of uclibc,
  91. # Which requires you to do this.
  92. # Make dynamic arm executables work (and x86 executables not work) in the chroot.
  93. ##### cp sd/lib/ld-uClibc.so.0 sd/lib/ld-linux.so.2
  94. # Only the binutils and the 4.2.4 gcc on the tarball were compiled this way.
  95. # So if we replace them with gcc-4.4.7 and new binutils, we should be ok.
  96. # Then we can drop some things into the chroot from the x86 host linux for speed.
  97. # I'm thinking maybe x86 bash and make could speed things up a little.
  98.  
  99. # Copy the required qemu binaries into the chroot;
  100. #cp /usr/bin/qemu-arm ./sd/usr/bin;
  101. cp /usr/bin/qemu-arm-static ./sd/usr/bin/
  102. # Give qemu-arm-static a few aliases, for good luck.
  103. cp /usr/bin/qemu-arm-static ./sd/usr/bin/qemu-arm
  104. cp /usr/bin/qemu-arm-static ./sd/qemu-wrapper
  105.  
  106. # Now step into the IZ2S chroot and get busy.
  107. sudo chroot sd
  108.  
  109. # Do some extra setup make the chroot useable.
  110. cd bin
  111. busybox ln busybox ln
  112. ln bash sh
  113. # Set up normal IZ2S busybox links.
  114. busybox.sh
  115. # IZ2S skips some busybox apps that are preinstalled on the internal ramdisk.
  116. # There is no ramdisk in qemu, so link them to this busybox.
  117. ln -s busybox chmod
  118. ln -s busybox rm
  119. ln -s busybox cp
  120. ln -s busybox mv
  121. ln -s busybox cat
  122. ln -s busybox mkdir
  123. ln -s busybox uname
  124. ln -s busybox ash
  125. ln -s busybox dd
  126. ln -s busybox df
  127. ln -s busybox echo
  128. ln -s busybox ls
  129. ln -s busybox mknod
  130. ln -s busybox mount
  131. ln -s busybox ping
  132. ln -s busybox ps
  133. ln -s busybox pwd
  134. ln -s busybox rmdir
  135. ln -s busybox sleep
  136. ln -s busybox sync
  137. ln -s busybox tar
  138. ln -s busybox umount
  139. ln -s busybox vi
  140. # I don't think we want this one.  Use binutils instead?
  141. rm /mnt/sd0/bin/ar
  142.  
  143. cd /
  144. mkdir mnt
  145. ln / mnt/sd0
  146. mkdir dev
  147. sudo mount -o bind /dev dev
  148. mkdir tmp
  149. sudo mount -o bind /tmp tmp
  150.  
  151. #############################################################################
  152. # Now get a compiler toolchain working.  Skip this if gcc-4.4.7 already built.
  153. # Or install the 100MB tarball with gcc-4.4.7 already built.
  154. #############################################################################
  155.  
  156. # We need the make program available to build things.
  157. cp /mnt/sd0/share/gcc/bin/make /usr/local/bin
  158.  
  159. # Need some non-stripped libs, AND INCLUDES.
  160. ln -s /usr/local/lib /usr/lib
  161. # These were supplied with (or by) uclibc and are needed to build a compiler.
  162. cp /share/gcc/lib/*crt*.o /lib
  163. cp /share/gcc/lib/libc.so /lib
  164. cp /share/gcc/lib/uclibc_nonshared.a /lib
  165. cp /share/gcc/lib/libpthread.* /lib
  166. cp /share/gcc/lib/libm.* /lib
  167.  
  168. export LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
  169.  
  170. ln -s /share/gcc/include /usr/include
  171. export CPATH=/usr/include:/usr/local/include  
  172.  
  173. cd gcc-4.4.7
  174.  
  175. # Manually apply the "index" patch for uclibc. (#undef index in rope, ropeimpl.h)
  176.  
  177. #./configure --prefix=/mnt/sd0/usr/local --target=arm-linux-uclibc --enable-languages=c,c++
  178. . ./env.sh
  179. ./cfg.sh
  180. make
  181. make install
  182.  
  183. # I made the mistake of using the gcc-4.2.4 to build my gcc-4.4.7, which
  184. # meant it could compile executables for IZ2S, but required ld-linux.so.2 for
  185. # itself in the chroot.  
  186. # So I did a make depclean and had 4.4.7 rebuild itself for ld-uclibc.so.0
  187. #
  188. # I also discovered binutils had been built with gcc-4.2.4 for ld-linux.so.2
  189. # so I rebuilt them with the same env and config settings as gcc-4.4.7.
  190. cd /binutils*
  191. ../gcc-4.4.7/cfg.sh
  192. make
  193. make install
  194.  
  195.  
  196. #############################################################################
  197. # At this point I cleaned up by removing all the various gcc-4.*.* directories.
  198. # I also deleted the source tarballs (*.gz) from / in the chroot.
  199. # Then I tracked down any installed gcc-4.2.4 stuff and deleted it.
  200. find  / -print |grep "4\.2\.4"
  201. # Also delete the binutils compiled with 4.2.4 (on Nov 28) from /share/gcc/lib
  202. cd /share/gcc/lib
  203. rm ranlib
  204. rm objdump
  205. rm ar
  206. rm strip
  207. rm objcopy
  208. rm nm
  209. rm as
  210. rm ld.bfd
  211. rm ld
  212.  
  213. # I still need to figure which libs in /share/gcc/lib belong to uclibc.
  214. # These must eventually be copied to /usr/local/lib for gcc-4.4.7 to find them.
  215.  
  216.  
  217.  
  218.  
  219.  
  220. # Remove old gcc from paths
  221. export CPLUS_INCLUDE_PATH=
  222. export LD_LIBRARY_PATH=/mnt/sd0/usr/local/lib:/mnt/sd0/lib
  223. export C_INCLUDE_PATH=/mnt/sd0/usr/local/include
  224. export PATH=/mnt/sd0/bin:/mnt/sd0/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  225.  
  226.  
  227.  
  228.  
  229. #############################################################################
  230. # To test I went into the stella directory and configured it like this.
  231. cd /stella-3.9.2
  232. ./configure --prefix=/usr/local --disable-windowed --disable-gl --disable-joystick --disable-debugger --x-libraries=
  233.  
  234. # It still wanted X11 so edited config.mak
  235. # Removed -DHAVE_X11 from DEFINES and remove -lX11 from LIBS
  236. # Hopefully it really only needs SDL.
  237. make
  238.  
  239. # Patched Settings.cxx to add some #ifdef DEBUGGER_SUPPORT
  240. make
  241.  
  242. # Hit some more extensive debugger issues.  Gave up on --disable-debugger
  243. ./configure --prefix=/usr/local --disable-windowed --disable-gl --disable-joystick --x-libraries=
  244. # Remove X11 from config.mak again
  245. make
  246.  
  247. # This was moving along ok so...
  248. # I visited the stella web site, looked at some screenshots, and aborted.
  249. # There's no way that enormous debugger screen is gonna fit on the zipit.
  250. # I think it'd be better to build from the dingux or gcw-zero stella code.
  251.  
  252. # So I tried to build openmsx instead.  
  253. cd /openmsx-0.9.1
  254. ./compile
  255. # It complained about python.
  256. # So I ran python and discovered it wanted libutil.so.0.
  257. cp /share/gcc/lib/libutil.* /usr/local/lib
  258. ./compile
  259. # Warning!  Do not interrupt this or you will have to start over from scratch.
  260. # The idiotic compile script does not resume from where it was interrupted.
  261.  
  262. # And naturally it complained about librt after 2 hours of compiling...
  263. cp /share/gcc/lib/librt.* /usr/local/lib
  264. ./compile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement