aboutsummaryrefslogtreecommitdiff
path: root/docs/CYGWIN_GUIDE.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/CYGWIN_GUIDE.md')
-rw-r--r--docs/CYGWIN_GUIDE.md352
1 files changed, 0 insertions, 352 deletions
diff --git a/docs/CYGWIN_GUIDE.md b/docs/CYGWIN_GUIDE.md
deleted file mode 100644
index 05d71961a..000000000
--- a/docs/CYGWIN_GUIDE.md
+++ /dev/null
@@ -1,352 +0,0 @@
1#Planck Advanced (but not too advanced) `cygwin` Users Guide
2If 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
4This 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`.
5
6#####Do not skip steps. Do not move past a step until the previous step finishes successfully.
7
8Based on [avr-libc installation guide](http://www.nongnu.org/avr-libc/user-manual/install_tools.html)
9
10##Get the Required Packages
11Download 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:
12- devel/git
13- devel/gcc-core
14- devel/gcc-g++
15- devel/flex
16- devel/bison
17- devel/make
18- devel/texinfo
19- devel/gettext-devel
20- devel/automake
21- devel/autoconfig
22- devel/libtool
23- text/gettext
24- libs/libgcc1
25- interpreters/m4
26- web/wget
27- archive/unzip
28
29The following sources will be required:
30- [gmp](https://gmplib.org/) (6.1.0)
31- [mpfr](http://www.mpfr.org/) (3.1.4)
32- [mpc](http://www.multiprecision.org/) (1.0.3)
33- [binutils](https://www.sourceware.org/binutils/) (2.26)
34- [gcc](https://gcc.gnu.org/) (5.3.0)
35- [avr-libc](http://www.nongnu.org/avr-libc/) (2.0.0)
36
37The `dfu-programmer` will be required to flash the new firmware
38- [dfu-programmer](https://dfu-programmer.github.io/) (0.7.2)
39
40The 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
41```
42$ mkdir ~/local
43$ mkdir ~/local/avr
44$ mkdir ~/src
45$ cd ~/src
46$ wget https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2
47$ wget http://www.mpfr.org/mpfr-3.1.4/mpfr-3.1.4.tar.bz2
48$ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
49$ wget http://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz
50$ wget http://mirror0.babylon.network/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.gz
51$ wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2
52$ tar -xjf gmp-6.1.0.tar.bz2
53$ tar -xjf mpfr-3.1.4.tar.bz2
54$ tar -zxf mpc-1.0.3.tar.gz
55$ tar -zxf binutils-2.26.tar.gz
56$ tar -zxf gcc-5.3.0.tar.gz
57$ tar -xjf avr-libc-2.0.0.tar.bz2
58```
59
60##Setup the Build Environment
61These 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.
62```
63$ PREFIX=$HOME/local/avr
64$ export PREFIX
65$ PATH=/usr/local/bin:/usr/local/lib:/usr/local/include:/bin:/lib:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS
66$ PATH=$PATH:$PREFIX/bin:$PREFIX/lib
67$ export PATH
68```
69
70##The `gcc` Required Math Library Packages
71The 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.
72
73###Build and Install `gmp`
74```
75$ cd ~/src/gmp-6.1.0
76$ ./configure --enable-static --disable-shared
77$ make
78$ make check
79$ make install
80```
81
82###Build and Install `mpfr`
83```
84$ cd ~/src/mpfr-3.1.4
85$ ./configure --with-gmp-build=../gmp-6.1.0 --enable-static --disable-shared
86$ make
87$ make check
88$ make install
89```
90
91###Build and Install `mpc`
92```
93$ cd ~/src/mpc-1.0.3
94$ ./configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-static --disable-shared
95$ make
96$ make check
97$ make install
98```
99
100##OPTIONAL Part
101You 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).
102
103###Build and Install `gcc` for Your Machine
104```
105$ cd ~/src/gcc-5.3.0
106$ mkdir obj-local
107$ cd obj-local
108$ ../configure --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-static --disable-shared
109$ make
110$ make install
111```
112##End OPTIONAL Part
113
114###Build and Install `binutils` for Your Machine
115```
116$ cd ~/src/binutils-2.26
117$ mkdir obj-local
118$ cd obj-local
119$ ../configure
120$ make
121$ make install
122```
123
124##Buliding `binutils`, `gcc`, and `avr-libc` for the AVR system
125Now 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.
126
127###Build `binutils` for AVR
128If 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`
129```
130$ cd ~/src/binutils-2.26
131$ mkdir obj-avr
132$ cd obj-avr
133$ ../configure --prefix=$PREFIX --target=avr --disable-nls
134$ make
135$ make install
136```
137
138###Build `gcc` for AVR
139```
140$ cd ~/src/gcc-5.3.0
141$ mkdir obj-avr
142$ cd obj-avr
143$ ../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
144$ make
145$ make install
146```
147
148###Build `avr-libc` for AVR
149For 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`.
150```
151$ cd ~/src/avr-libc-2.0.0
152$ ./configure --prefix=$PREFIX --build=x86_64-unknown-cygwin --host=avr
153$ make
154$ make install
155```
156
157##Building 'dfu-programmer' for flashing the firmware via USB and installing the drivers
158We 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.
159
160### Build and Install the `libusb`
161The `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.
162```
163$ cd ~/src
164$ git clone https://github.com/libusb/libusb.git
165$ cd libusb
166$ ./bootstrap.sh
167$ ./configure
168$ make
169$ make install
170```
171
172### Build and Install the `dfu-programmer`
173```
174$ cd ~/src
175$ git clone https://github.com/dfu-programmer/dfu-programmer.git
176$ cd dfu-programmer
177$ ./bootstrap.sh
178$ ./configure
179$ make
180$ make install
181```
182
183Verify the installation with:
184```
185$ which dfu-programmer
186/usr/local/bin/dfu-programmer
187
188$ dfu-programmer
189dfu-programmer 0.7.2
190https://github.com/dfu-programmer/dfu-programmer
191Type 'dfu-programmer --help' for a list of commands
192 'dfu-programmer --targets' to list supported target devices
193```
194If you are not getting the above result, you will not be able to flash the firmware!
195
196###Install the USB drivers
197The 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).
198```
199$ cd ~/src
200$ wget http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip
201$ unzip dfu-programmer-win-0.7.2.zip -d dfu-programmer-win-0.7.2
202```
203
204or
205
206The 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`.
207
208Then, 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:
209```
210C:\> pnputil -i -a C:\cygwin64\home\Kevin\src\dfu-programmer-win-0.7.2\dfu-prog-usb-1.2.2\atmel_usb_dfu.inf
211or
212C:\> pnputil -i -a "C:\Program Files (x86)\Atmel\Flip 3.4.7\usb\atmel_usb_dfu.inf"
213```
214
215This should be the result:
216```
217Microsoft PnP Utility
218
219Processing inf : atmel_usb_dfu.inf
220Successfully installed the driver on a device on the system.
221Driver package added successfully.
222Published name : oem104.inf
223
224
225Total attempted: 1
226Number successfully imported: 1
227```
228
229Alternatively, 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.
230
231##Building and Flashing the Planck firmware!
232If you did everything else right. This part should be a snap! Grab the latest sources from `github`, make the Plank firmware, then flash it.
233
234###Build Planck and Load the Firmware
235```
236$ cd ~/src
237$ git clone https://github.com/qmk/qmk_firmware.git
238$ cd qmk_firmware/keyboards/planck
239$ make
240```
241
242Make sure there are no errors. You should end up with this or something similar:
243```
244Creating load file for Flash: planck.hex
245avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature planck.elf planck.hex
246
247Creating load file for EEPROM: planck.eep
248avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
249--change-section-lma .eeprom=0 --no-change-warnings -O ihex planck.elf planck.eep || exit 0
250
251Creating Extended Listing: planck.lss
252avr-objdump -h -S -z planck.elf > planck.lss
253
254Creating Symbol Table: planck.sym
255avr-nm -n planck.elf > planck.sym
256
257Size after:
258 text data bss dec hex filename
259 18602 82 155 18839 4997 planck.elf
260
261-------- end --------
262```
263
264If 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.
265
266But if everything went OK, you are ready to flash! Press the reset button on the bottom of the Planck, wait two seconds, then:
267```
268$ make dfu
269```
270.
271.
272.
273profit!!!
274
275
276
277
278
279##extra bits...
280
281###Installing Precompiled `dfu-programmer` Binaries (not recommended for `cygwin`)
282To 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)).
283
284Copy 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):
285```
286C:\> set PATH=%PATH%;C:\cygwin64\home\Kevin\local\avr\bin
287```
288
289Then, rename `libusb0_x86.dll` to `libusb0.dll`.
290
291You can tell that you were successful by trying to execute 'dfu-programmer' from the 'cygwin' prompt:
292```
293$ which dfu-programmer
294/home/Kevin/local/avr/bin/dfu-programmer
295
296$ dfu-programmer
297dfu-programmer 0.7.2
298https://github.com/dfu-programmer/dfu-programmer
299Type 'dfu-programmer --help' for a list of commands
300 'dfu-programmer --targets' to list supported target devices
301```
302
303If you are not getting the above result, you will not be able to flash the firmware!
304- Try making sure your `PATH` variables are set correctly for both `Windows` and `cygwin`.
305- Make sure the `dll` is named correctly.
306- 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`.
307- Still have problems? Try building it instead.
308
309
310##Debugging Tools
311
312These 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.
313
314### `gdb` for AVR
315`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.
316
317```
318$ cd ~/src
319$ git clone git://sourceware.org/git/binutils-gdb.git
320$ cd binutils-gdb
321$ mkdir obj-avr
322$ cd obj-avr
323$ ../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
324$ make
325$ make install
326```
327
328### `simulavr`
329`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.
330
331This 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`.
332
333
334```
335$ cd ~/src
336$ git clone https://github.com/Traumflug/simulavr.git
337$ cd simulavr
338$ ./bootstrap
339$ ./configure --prefix=$PREFIX --enable-static --disable-tcl --disable-doxygen-doc
340```
341 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.
342
343```
344$ make
345$ make install
346```
347
348
349TODO:
350- git repos for all sources
351- command line magic for cygwin setup
352- better options for `dfu-drivers`