upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

CYGWIN_GUIDE.md 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. #Planck Advanced (but not too advanced) `cygwin` Users Guide
  2. If you are a user of the [cygwin environment](https://cygwin.com) in Windows and want the freedom to use the latest tools available, then this is the guide for you. If compiling your own copy of the latest and greatest Gnu C Compiler makes you super happy, then this is the guide for you. If the command line make you smile, then this is the guide for you.
  3. This guide was written step by step as I went through the process on a `Windows 10` `x86_64` and a `Windows 7` `amd k10` based system. This should be generally applicable to to any `Windows` environment with `cygwin`.
  4. #####Do not skip steps. Do not move past a step until the previous step finishes successfully.
  5. Based on [avr-libc installation guide](http://www.nongnu.org/avr-libc/user-manual/install_tools.html)
  6. ##Get the Required Packages
  7. Download the `cygwin` setup ([x86_64](https://cygwin.com/setup-x86_64.exe)) and install the default system plus the following if they are not already selected:
  8. - devel/git
  9. - devel/gcc-core
  10. - devel/gcc-g++
  11. - devel/flex
  12. - devel/bison
  13. - devel/make
  14. - devel/texinfo
  15. - devel/gettext-devel
  16. - devel/automake
  17. - devel/autoconfig
  18. - devel/libtool
  19. - text/gettext
  20. - libs/libgcc1
  21. - interpreters/m4
  22. - web/wget
  23. - archive/unzip
  24. The following sources will be required:
  25. - [gmp](https://gmplib.org/) (6.1.0)
  26. - [mpfr](http://www.mpfr.org/) (3.1.4)
  27. - [mpc](http://www.multiprecision.org/) (1.0.3)
  28. - [binutils](https://www.sourceware.org/binutils/) (2.26)
  29. - [gcc](https://gcc.gnu.org/) (5.3.0)
  30. - [avr-libc](http://www.nongnu.org/avr-libc/) (2.0.0)
  31. The `dfu-programmer` will be required to flash the new firmware
  32. - [dfu-programmer](https://dfu-programmer.github.io/) (0.7.2)
  33. The set of commands below will create a directory (`~/local/avr`) for the sources you compile to be installed on the machine and a directory (`~/src`) for these source files to be stored. The commands then download the sources of the needed packages and unpack them. Note: the expand commands are different depending on if the packages are offered as a `bz2` or `gz` archive
  34. ```
  35. $ mkdir ~/local
  36. $ mkdir ~/local/avr
  37. $ mkdir ~/src
  38. $ cd ~/src
  39. $ wget https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2
  40. $ wget http://www.mpfr.org/mpfr-3.1.4/mpfr-3.1.4.tar.bz2
  41. $ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
  42. $ wget http://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz
  43. $ wget http://mirror0.babylon.network/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.gz
  44. $ wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2
  45. $ tar -xjf gmp-6.1.0.tar.bz2
  46. $ tar -xjf mpfr-3.1.4.tar.bz2
  47. $ tar -zxf mpc-1.0.3.tar.gz
  48. $ tar -zxf binutils-2.26.tar.gz
  49. $ tar -zxf gcc-5.3.0.tar.gz
  50. $ tar -xjf avr-libc-2.0.0.tar.bz2
  51. ```
  52. ##Setup the Build Environment
  53. These commands will set up the install directory and the `PATH` variable, which will allow you to access your installed packages. Note: if you close the `cygwin` terminal window, you will need to rerun these commands, they are not permanent.
  54. ```
  55. $ PREFIX=$HOME/local/avr
  56. $ export PREFIX
  57. $ PATH=/usr/local/bin:/usr/local/lib:/usr/local/include:/bin:/lib:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS
  58. $ PATH=$PATH:$PREFIX/bin:$PREFIX/lib
  59. $ export PATH
  60. ```
  61. ##The `gcc` Required Math Library Packages
  62. The following packages are required to be complied and installed in order to compile `gcc`. They are not sufficiently available through the `cygwin` package system, so we have to make them ourselves. They must be complied in this order because each one depends on the previous. Verfiy that for each package, `make check` returns all passing and no fails.
  63. ###Build and Install `gmp`
  64. ```
  65. $ cd ~/src/gmp-6.1.0
  66. $ ./configure --enable-static --disable-shared
  67. $ make
  68. $ make check
  69. $ make install
  70. ```
  71. ###Build and Install `mpfr`
  72. ```
  73. $ cd ~/src/mpfr-3.1.4
  74. $ ./configure --with-gmp-build=../gmp-6.1.0 --enable-static --disable-shared
  75. $ make
  76. $ make check
  77. $ make install
  78. ```
  79. ###Build and Install `mpc`
  80. ```
  81. $ cd ~/src/mpc-1.0.3
  82. $ ./configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-static --disable-shared
  83. $ make
  84. $ make check
  85. $ make install
  86. ```
  87. ##OPTIONAL Part
  88. You can build and install a brand new `gcc` or you can use the one supplied by `cygwin`. This will take about 4-5 hours to compile (It is a "native build", so it does the entire build **3 times**. This takes a long while).
  89. ###Build and Install `gcc` for Your Machine
  90. ```
  91. $ cd ~/src/gcc-5.3.0
  92. $ mkdir obj-local
  93. $ cd obj-local
  94. $ ../configure --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-static --disable-shared
  95. $ make
  96. $ make install
  97. ```
  98. ##End OPTIONAL Part
  99. ###Build and Install `binutils` for Your Machine
  100. ```
  101. $ cd ~/src/binutils-2.26
  102. $ mkdir obj-local
  103. $ cd obj-local
  104. $ ../configure
  105. $ make
  106. $ make install
  107. ```
  108. ##Buliding `binutils`, `gcc`, and `avr-libc` for the AVR system
  109. Now we can make the critical stuff for compiling our firmware: `binutils`, `gcc`, and `avr-libc` for the AVR architecture. These allow us to build and manipulate the firmware for the keyboard.
  110. ###Build `binutils` for AVR
  111. If you plan to build and install `avr-gdb` also, use the `gdb` install at the end of this guide as it also builds the `binutils`
  112. ```
  113. $ cd ~/src/binutils-2.26
  114. $ mkdir obj-avr
  115. $ cd obj-avr
  116. $ ../configure --prefix=$PREFIX --target=avr --disable-nls
  117. $ make
  118. $ make install
  119. ```
  120. ###Build `gcc` for AVR
  121. ```
  122. $ cd ~/src/gcc-5.3.0
  123. $ mkdir obj-avr
  124. $ cd obj-avr
  125. $ ../configure --prefix=$PREFIX --target=avr --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-static --disable-shared --disable-nls --disable-libssp --with-dwarf2
  126. $ make
  127. $ make install
  128. ```
  129. ###Build `avr-libc` for AVR
  130. For building the `avr-libc`, we have to specify the host build system. In my case it is `x86_64-unknown-cygwin`. You can look for build system type in the `gcc` configure notes for the proper `--build` specification to pass when you configure `avr-libc`.
  131. ```
  132. $ cd ~/src/avr-libc-2.0.0
  133. $ ./configure --prefix=$PREFIX --build=x86_64-unknown-cygwin --host=avr
  134. $ make
  135. $ make install
  136. ```
  137. ##Building 'dfu-programmer' for flashing the firmware via USB and installing the drivers
  138. We can either build our own, or use the precomplied binaries. The precompiled binaries don't play well with `cygwin` so it is better to build them ourselves. The procedure for the precompiled binaries is included at the end of this guide.
  139. ### Build and Install the `libusb`
  140. The `dfu-programmer` requires `libusb` so that it can interact with the USB system. These repos must be bootstrapped in order to create an appropriate `./configure` and `Makefile` for your system.
  141. ```
  142. $ cd ~/src
  143. $ git clone https://github.com/libusb/libusb.git
  144. $ cd libusb
  145. $ ./bootstrap.sh
  146. $ ./configure
  147. $ make
  148. $ make install
  149. ```
  150. ### Build and Install the `dfu-programmer`
  151. ```
  152. $ cd ~/src
  153. $ git clone https://github.com/dfu-programmer/dfu-programmer.git
  154. $ cd dfu-programmer
  155. $ ./bootstrap.sh
  156. $ ./configure
  157. $ make
  158. $ make install
  159. ```
  160. Verify the installation with:
  161. ```
  162. $ which dfu-programmer
  163. /usr/local/bin/dfu-programmer
  164. $ dfu-programmer
  165. dfu-programmer 0.7.2
  166. https://github.com/dfu-programmer/dfu-programmer
  167. Type 'dfu-programmer --help' for a list of commands
  168. 'dfu-programmer --targets' to list supported target devices
  169. ```
  170. If you are not getting the above result, you will not be able to flash the firmware!
  171. ###Install the USB drivers
  172. The drivers are included in the windows binary version of [`dfu-programmer` 0.7.2](http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip).
  173. ```
  174. $ cd ~/src
  175. $ wget http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip
  176. $ unzip dfu-programmer-win-0.7.2.zip -d dfu-programmer-win-0.7.2
  177. ```
  178. or
  179. The official drivers are found in [Atmel's `FLIP` installer](http://www.atmel.com/images/Flip%20Installer%20-%203.4.7.112.exe). Download and then install `FLIP`. Upon installation, the drivers will be found in `C:\Program Files (x86)\Atmel\Flip 3.4.7\usb`.
  180. Then, from an **administrator-privileged** `Windows` terminal, run the following command (adjust the path for username, etc. as necessary) and accept the prompt that pops up:
  181. ```
  182. C:\> pnputil -i -a C:\cygwin64\home\Kevin\src\dfu-programmer-win-0.7.2\dfu-prog-usb-1.2.2\atmel_usb_dfu.inf
  183. or
  184. C:\> pnputil -i -a "C:\Program Files (x86)\Atmel\Flip 3.4.7\usb\atmel_usb_dfu.inf"
  185. ```
  186. This should be the result:
  187. ```
  188. Microsoft PnP Utility
  189. Processing inf : atmel_usb_dfu.inf
  190. Successfully installed the driver on a device on the system.
  191. Driver package added successfully.
  192. Published name : oem104.inf
  193. Total attempted: 1
  194. Number successfully imported: 1
  195. ```
  196. Alternatively, the `Windows` driver can be installed when prompted by `Windows` when the keyboard is attached. Do not let `Windows` search for a driver; specify the path to search for a driver and point it to the `atmel_usb_dfu.inf` file.
  197. ##Building and Flashing the Planck firmware!
  198. If you did everything else right. This part should be a snap! Grab the latest sources from `github`, make the Plank firmware, then flash it.
  199. ###Build Planck and Load the Firmware
  200. ```
  201. $ cd ~/src
  202. $ git clone https://github.com/jackhumbert/qmk_firmware.git
  203. $ cd qmk_firmware/keyboard/planck
  204. $ make
  205. ```
  206. Make sure there are no errors. You should end up with this or something similar:
  207. ```
  208. Creating load file for Flash: planck.hex
  209. avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature planck.elf planck.hex
  210. Creating load file for EEPROM: planck.eep
  211. avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  212. --change-section-lma .eeprom=0 --no-change-warnings -O ihex planck.elf planck.eep || exit 0
  213. Creating Extended Listing: planck.lss
  214. avr-objdump -h -S -z planck.elf > planck.lss
  215. Creating Symbol Table: planck.sym
  216. avr-nm -n planck.elf > planck.sym
  217. Size after:
  218. text data bss dec hex filename
  219. 18602 82 155 18839 4997 planck.elf
  220. -------- end --------
  221. ```
  222. If you do not get the above, you **did not** build the firmware, and you will have nothing to flash. If you have the fresh clone from `github`, it was probably something gone wrong in this install process, go check and see what didn't work and threw errors or what steps you might have missed.
  223. But if everything went OK, you are ready to flash! Press the reset button on the bottom of the Planck, wait two seconds, then:
  224. ```
  225. $ make dfu
  226. ```
  227. .
  228. .
  229. .
  230. profit!!!
  231. ##extra bits...
  232. ###Installing Precompiled `dfu-programmer` Binaries (not recommended for `cygwin`)
  233. To install the `dfu-programmer` from the binaries, we must get if from [the `dfu-programmer` website](https://dfu-programmer.github.io/) ([0.7.2](http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip)).
  234. Copy this file into your `cygwin` home\src directory. (For me, it is `C:\cygwin64\home\Kevin\src`), extract the files, move `dfu-programmer.exe` to `~/local/avr/bin`. Most obnoxiously, the `libusb0_x86.dll` and `libusb0.sys` need to be moved from `./dfu-prog-usb-1.2.2/x86/` to a directory in the `Windows` `PATH` and the `cygwin` `PATH`. This is because the `dfu-programmer` binary is `mingw` based, not `cygwin` based, so the `dlls` do not cooperate. I achieved acceptable pathing by moving the files to `C:\cygwin64\home\Kevin\local\avr\bin` Then, in a `WINDOWS` command prompt running (Adjusting your path for username, etc. as needed):
  235. ```
  236. C:\> set PATH=%PATH%;C:\cygwin64\home\Kevin\local\avr\bin
  237. ```
  238. Then, rename `libusb0_x86.dll` to `libusb0.dll`.
  239. You can tell that you were successful by trying to execute 'dfu-programmer' from the 'cygwin' prompt:
  240. ```
  241. $ which dfu-programmer
  242. /home/Kevin/local/avr/bin/dfu-programmer
  243. $ dfu-programmer
  244. dfu-programmer 0.7.2
  245. https://github.com/dfu-programmer/dfu-programmer
  246. Type 'dfu-programmer --help' for a list of commands
  247. 'dfu-programmer --targets' to list supported target devices
  248. ```
  249. If you are not getting the above result, you will not be able to flash the firmware!
  250. - Try making sure your `PATH` variables are set correctly for both `Windows` and `cygwin`.
  251. - Make sure the `dll` is named correctly.
  252. - Do not extract it with `cygwin`'s `unzip` as it does not set the executable permission. If you did it anyway, do `chmod +x dfu-programmer.exe`.
  253. - Still have problems? Try building it instead.
  254. ##Debugging Tools
  255. These tools are for debugging your firmware, etc. before flashing. Theoretically, it can save your memory from wearing out. However, these tool do not work 100% for the Planck firmware.
  256. ### `gdb` for AVR
  257. `gdb` has a simulator for AVR but it does not support all instructions (like WDT), so it immediately crashes when running the Planck firmware (because `lufa.c` disables the WDT in the first few lines of execution). But it can still be useful in debugging example code and test cases, if you know how to use it.
  258. ```
  259. $ cd ~/src
  260. $ git clone git://sourceware.org/git/binutils-gdb.git
  261. $ cd binutils-gdb
  262. $ mkdir obj-avr
  263. $ cd obj-avr
  264. $ ../configure --prefix=$PREFIX --target=avr --build=x86_64-unknown-cygwin --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --disable-nls --enable-static
  265. $ make
  266. $ make install
  267. ```
  268. ### `simulavr`
  269. `simulavr` is an AVR simulator. It runs the complied AVR elfs. `simulavr` does not support the `atmega32u4` device... it does `atmega32` but that is not good enough for the firmware (no PORTE and other things), so you cannot run the Planck firmware. I use it to simulate ideas I have for features in separate test projects.
  270. This one is a major pain in the butt because it has a lot of dependencies and it is buggy. I will do my best to explain it but... it was hard to figure out. A few things need to be changed in the 'Makefile' to make it work in `cygwin`.
  271. ```
  272. $ cd ~/src
  273. $ git clone https://github.com/Traumflug/simulavr.git
  274. $ cd simulavr
  275. $ ./bootstrap
  276. $ ./configure --prefix=$PREFIX --enable-static --disable-tcl --disable-doxygen-doc
  277. ```
  278. Edit `src/Makefile.am` now so that `-no-undefined` is included (I did this by removing the SYS_MINGW conditional surrounding `libsim_la_LDFLAGS += -no-undefined` and `libsimulavr_la_LDFLAGS += -no-undefined \ libsimulavr_la_LIBADD += $(TCL_LIB)`. Also, `$(EXEEXT)` is added after `kbdgentables` in two places.
  279. ```
  280. $ make
  281. $ make install
  282. ```
  283. TODO:
  284. - git repos for all sources
  285. - command line magic for cygwin setup
  286. - better options for `dfu-drivers`