]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboard/planck/CYGWIN_GUIDE.md
Cygwin Based Users Guidev0.2 -formatting revisions
[qmk_firmware.git] / keyboard / planck / CYGWIN_GUIDE.md
1 #Planck Advanced (but not too advanced) `cygwin` Users Guide\r
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.\r
3 \r
4 \r
5 This guide was written step by step as I went through the process on a `Windows 10` `x86_64` based system.  This should be generally applicable to to any `Windows` environment with `cygwin`.\r
6 \r
7 \r
8 #####Do not skip steps. Do not move past a step until the previous step finishes successfully.\r
9 \r
10 \r
11 \r
12 Based on [avr-libc installation guide](http://www.nongnu.org/avr-libc/user-manual/install_tools.html)\r
13 \r
14 \r
15 ##Get the Required Packages\r
16 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:\r
17 - devel/gcc-core\r
18 - devel/gcc-g++\r
19 - devel/flex\r
20 - devel/git\r
21 - libs/libglib2.0_0\r
22 - libs/libgcc1\r
23 - interpreters/m4\r
24 - web/wget\r
25 \r
26 The following sources will be required:\r
27 - [gmp](https://gmplib.org/) (6.1.0)\r
28 - [mpfr](http://www.mpfr.org/) (3.1.3)\r
29 - [mpc](http://www.multiprecision.org/) (1.0.3) \r
30 - [binutils](https://www.sourceware.org/binutils/) (2.26)\r
31 - [gcc](https://gcc.gnu.org/) (5.3.0)\r
32 - [avr-libc](http://www.nongnu.org/avr-libc/) (2.0.0)\r
33 \r
34 The `dfu-programmer` will be required to flash the new firmware \r
35 - [dfu-programmer](https://dfu-programmer.github.io/) (0.7.2)\r
36 \r
37 \r
38 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\r
39 \r
40 ```\r
41 $ mkdir ~/local/avr\r
42 $ mkdir ~/src\r
43 $ cd ~/src\r
44 $ wget https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2\r
45 $ wget http://www.mpfr.org/mpfr-current/mpfr-3.1.3.tar.bz2\r
46 $ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz\r
47 $ wget http://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz\r
48 $ wget http://mirror0.babylon.network/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.gz\r
49 $ wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.0.0.tar.bz2\r
50 $ tar -xjf gmp-6.1.0.tar.bz2\r
51 $ tar -xjf mpfr-3.1.3.tar.bz2\r
52 $ tar -zxf mpc-1.0.3.tar.gz\r
53 $ tar -zxf binutils-2.26.tar.gz\r
54 $ tar -zxf gcc-5.3.0.tar.gz\r
55 $ tar -xjf avr-libc-2.0.0.tar.bz2 \r
56 ```\r
57 \r
58 ##Setup the Build Environment\r
59 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.\r
60 ```\r
61 $ PREFIX=$HOME/local/avr\r
62 $ export PREFIX\r
63 $ PATH=/usr/local/bin:/usr/local/lib:/usr/local/include:/bin:/lib:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS\r
64 $ PATH=$PATH:$PREFIX/bin\r
65 $ export PATH\r
66 ```\r
67 \r
68 ##The `gcc` Required Math Library Packages\r
69 The following packages are required to be complied and installed in order to compile `gcc`.  They are not 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.\r
70 \r
71 ###Build and Install `gmp`\r
72 ```\r
73 $ cd ~/src/gmp-6.1.0\r
74 $ ./configure --enable-static --disable-shared\r
75 $ make\r
76 $ make check\r
77 $ make install\r
78 ```\r
79 \r
80 ###Build and Install `mpfr`\r
81 ```\r
82 $ cd ~/src/mpfr-3.1.3\r
83 $ ./configure --with-gmp-build=../gmp-6.1.0 --enable-static --disable-shared\r
84 $ make\r
85 $ make check\r
86 $ make install\r
87 ```\r
88 \r
89 ###Build and Install `mpc`\r
90 ```\r
91 $ cd ~/src/mpc-1.0.3\r
92 $ ./configure --with-gmp=/usr/local --with-mpfr=/usr/local --enable-static --disable-shared\r
93 $ make\r
94 $ make check\r
95 $ make install\r
96 ```\r
97 \r
98 ##OPTIONAL Part\r
99 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). I would skip it.\r
100 ###Build and Install `gcc` on your Machine  \r
101 ```\r
102 $ cd ~/src/gcc-5.3.0\r
103 $ mkdir obj-local\r
104 $ cd obj-local\r
105 $ ../configure --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --enable-static --disable-shared\r
106 $ make\r
107 $ make install\r
108 ```\r
109 \r
110 ###Build and Install `binutils` on your Machine\r
111 ```\r
112 $ cd ~/src/binutils-2.26\r
113 $ mkdir obj-local\r
114 $ cd obj-local\r
115 $ ../configure\r
116 $ make\r
117 $ make install\r
118 ```\r
119 ##End OPTIONAL Part\r
120 \r
121 ##Buliding `binutils`, `gcc`, and `avr-libc` for the AVR system\r
122 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.\r
123 \r
124 ###Build `binutils` for AVR\r
125 ```\r
126 $ cd ~/src/binutils-2.26\r
127 $ mkdir obj-avr\r
128 $ cd obj-avr\r
129 $ ../configure --prefix=$PREFIX --target=avr --disable-nls\r
130 $ make\r
131 $ make install\r
132 ```\r
133 \r
134 ###Build `gcc` for AVR\r
135 ```\r
136 $ cd ~/src/gcc-5.3.0\r
137 $ mkdir obj-avr\r
138 $ cd obj-avr\r
139 $ ../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\r
140 $ make\r
141 $ make install\r
142 ```\r
143 \r
144 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`.\r
145 \r
146 ###Build `avr-libc` for AVR\r
147 ```\r
148 $ cd ~/src/avr-libc-2.0.0\r
149 $ ./configure --prefix=$PREFIX --build=x86_64-unknown-cygwin --host=avr\r
150 $ make\r
151 $ make install\r
152 ```\r
153 \r
154 ##Install `dfu-programmer`\r
155 To install the `dfu-programmer`, we must get if from [their website](https://dfu-programmer.github.io/) (no fancy command line tricks here, but [this](http://iweb.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/0.7.2/dfu-programmer-win-0.7.2.zip) might work).\r
156 Copy this file into your `cygwin` home directory.  (For me, it is `C:\cygwin64\home\Kevin`), 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/dfu-prog-usb-1.2.2/x86/` to a directory in the `Windows` `PATH` and the `cygwin` `PATH`. I achieved this by moving the files with Windows Explorer (you know, click and drag...) to  `C:\cygwin64\home\Kevin\local\avr\bin` Then, in a `WINDOWS` command prompt running:\r
157 ```\r
158 C:\> set PATH=%PATH%;C:\cygwin64\home\Kevin\local\avr\bin\r
159 ```\r
160 Adjust your path (for username) as needed. Also, `libusb0_x86.dll` needs to be renamed to `libusb0.dll`.  Why must this be so hard? You can tell that you were successful this way:\r
161 ```\r
162 $ which dfu-programmer\r
163 /home/Kevin/local/avr/bin/dfu-programmer\r
164 \r
165 $ dfu-programmer\r
166 dfu-programmer 0.7.2\r
167 https://github.com/dfu-programmer/dfu-programmer\r
168 Type 'dfu-programmer --help'    for a list of commands\r
169      'dfu-programmer --targets' to list supported target devices\r
170 ```\r
171 If you are not getting the above result, you will not be able to flash the firmware! \r
172 - Try making sure your `PATH` variables are set correctly for both `Windows` and `cygwin`. \r
173 - Do not extract it with `cygwin`'s `unzip` as it does not set the executable permissions correctly. If you did it anyway, do `chmod 755 dfu-programmer.exe`\r
174 \r
175 ####Install the USB drivers\r
176 These drivers are included in the `dfu-programmer` 0.7.2 (but you can get newer ones [here](http://iweb.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/1.2.6.0/libusb-win32-bin-1.2.6.0.zip)) and allow the `dfu-programmer` to program the firmware. From an **administrator-privileged** `Windows` terminal, run the following command (adjust the path as necessary) and accept the prompt that pops up:\r
177 ```\r
178 C:\> pnputil -i -a C:\cygwin64\home\Kevin\dfu-prog-usb-1.2.2\atmel_usb_dfu.inf\r
179 ```\r
180 This should be the result:\r
181 ```\r
182 Microsoft PnP Utility\r
183 \r
184 Processing inf :            atmel_usb_dfu.inf\r
185 Successfully installed the driver on a device on the system.\r
186 Driver package added successfully.\r
187 Published name :            oem104.inf\r
188 \r
189 \r
190 Total attempted:              1\r
191 Number successfully imported: 1\r
192 ```\r
193 \r
194 ##Building and Flashing the Planck firmware!\r
195 \r
196 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.\r
197 \r
198 ###Build Planck and Load the Firmware\r
199 ```\r
200 $ cd ~/src\r
201 $ git clone https://github.com/jackhumbert/qmk_firmware.git\r
202 $ cd qmk_firmware/keyboard/planck\r
203 $ make\r
204 ```\r
205 Make sure there are no errors.  You should end up with this or something similar:\r
206 \r
207 ```\r
208 Creating load file for Flash: planck.hex\r
209 avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature planck.elf planck.hex\r
210 \r
211 Creating load file for EEPROM: planck.eep\r
212 avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \\r
213 --change-section-lma .eeprom=0 --no-change-warnings -O ihex planck.elf planck.eep || exit 0\r
214 \r
215 Creating Extended Listing: planck.lss\r
216 avr-objdump -h -S -z planck.elf > planck.lss\r
217 \r
218 Creating Symbol Table: planck.sym\r
219 avr-nm -n planck.elf > planck.sym\r
220 \r
221 Size after:\r
222    text    data     bss     dec     hex filename\r
223   18602      82     155   18839    4997 planck.elf\r
224 \r
225 -------- end --------\r
226 ```\r
227 \r
228 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.\r
229 \r
230 But if everything went OK, you are ready to flash! Press the reset button on the bottom of the Planck, wait two seconds, then:\r
231 ```\r
232 $ make dfu\r
233 ```\r
234 .\r
235 .\r
236 .\r
237 profit!!!\r