added support for downloading to our custom bootloader
diff --git a/bbb_cape/src/cape/bootloader.c b/bbb_cape/src/cape/bootloader.c
index 199a3d1..39f3080 100644
--- a/bbb_cape/src/cape/bootloader.c
+++ b/bbb_cape/src/cape/bootloader.c
@@ -4,6 +4,7 @@
 
 #include "cape/bootloader_handoff.h"
 #include "cape/led.h"
+#include "cape/util.h"
 
 // Actually runs the bootloader code.
 // Implemented in bootloader_impl.c.
@@ -64,6 +65,7 @@
       RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN;
   led_init();
   led_set(LED_HB, 1);
+  gpio_set_pupd(GPIOC, 2, 2);
 
   setup_main_clock();
 
@@ -72,8 +74,8 @@
   while (!(SYSCFG->CMPCR & SYSCFG_CMPCR_READY)) {}  // wait for it to be ready
 
   if (GPIOC->IDR & (1 << 2)) {
-    jump_to_main();
-  } else {
     bootloader_start();
+  } else {
+    jump_to_main();
   }
 }
diff --git a/bbb_cape/src/cape/bootloader_impl.c b/bbb_cape/src/cape/bootloader_impl.c
index 1c1fde4..15d28b1 100644
--- a/bbb_cape/src/cape/bootloader_impl.c
+++ b/bbb_cape/src/cape/bootloader_impl.c
@@ -12,7 +12,7 @@
 // erases from MAIN_FLASH_START_SECTOR to MAIN_FLASH_END_SECTOR, and keeps
 // writing until MAIN_FLASH_END (if it gets data).
 //
-// The bootloader sends READY when it is first ready to receive bytes. It then
+// The bootloader sends a NACK when it is first ready to receive bytes. It then
 // expects DATA_BYTES-sized packets (+ the checksum calculated with the standard
 // CRC algorithm). When it successfully receives one and writes it out, it sends
 // ACK. If it has any errors, it waits until there's a 1-second gap (or it
@@ -22,7 +22,6 @@
 
 #define ACK 0x79
 #define NACK 0x1F
-#define READY 0x7F
 
 static void process_buffer(uint32_t *buffer) {
   static uint32_t *out_pointer = (uint32_t *)MAIN_FLASH_START;
@@ -67,7 +66,7 @@
   int error = 0;
   int bytes_received = 0;
 
-  uart_byte_send(READY);
+  uart_byte_send(NACK);
 
   while (1) {
     // Receive with a 1 second timeout.
diff --git a/bbb_cape/src/cape/util.h b/bbb_cape/src/cape/util.h
index d19a7e9..9188adb 100644
--- a/bbb_cape/src/cape/util.h
+++ b/bbb_cape/src/cape/util.h
@@ -57,6 +57,11 @@
   SET_BITS(port->MODER, 2, 0 /* input */, pin);
 }
 
+// dir: 0 => none, 1 => up, 2 => down
+static inline void gpio_set_pupd(GPIO_TypeDef *port, int pin, int dir) {
+  SET_BITS(port->PUPDR, 2, dir, pin);
+}
+
 // exti is which EXTI line to set
 // port is 0 for A, 1 for B, etc
 static inline void EXTI_set(int exti, int port) {