diff --git a/Makefile b/Makefile
index 9ce59068..5fa951e6 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,11 @@ INSTALL = install
 PREFIX  ?= /usr/local
 MANDIR  ?= $(PREFIX)/share/man
 BASHCOMPDIR ?= $(PREFIX)/share/bash-completion/completions
-CFLAGS  ?= -Os -Wall -Wextra -Wno-unused-parameter -Wshadow -Wmissing-prototypes -Wwrite-strings
+EXTRA_LIBS ?=
+override CFLAGS += -Wall -Winvalid-pch -Wextra -std=c99 -O3 -Wshadow -Wmissing-prototypes -Wwrite-strings -Wno-unused-parameter -Wno-address-of-packed-member -Wno-enum-conversion -Wno-missing-braces
+override CFLAGS += -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L -D_BSD_SOURCE -D__BSD_VISIBLE -D__XSI_VISIBLE -D_NETBSD_SOURCE -D_DARWIN_C_SOURCE
+override CFLAGS += -fPIC
+override CFLAGS += -DCONFIG_CROS_EC=1 -DUSE_BIG_LOCK=1
 EXPORTDIR ?= .
 RANLIB  ?= ranlib
 PKG_CONFIG ?= pkg-config
@@ -251,6 +255,7 @@ HAS_GETOPT          := $(call c_compile_test, Makefile.d/getopt_test.c)
 HAS_FT232H          := $(call c_compile_test, Makefile.d/ft232h_test.c, $(CONFIG_LIBFTDI1_CFLAGS))
 HAS_UTSNAME         := $(call c_compile_test, Makefile.d/utsname_test.c)
 HAS_CLOCK_GETTIME   := $(call c_compile_test, Makefile.d/clock_gettime_test.c)
+HAS_STRNLEN         := $(call c_compile_test, Makefile.d/strnlen_test.c)
 HAS_EXTERN_LIBRT    := $(call c_link_test, Makefile.d/clock_gettime_test.c, , -lrt)
 HAS_LINUX_MTD       := $(call c_compile_test, Makefile.d/linux_mtd_test.c)
 HAS_LINUX_SPI       := $(call c_compile_test, Makefile.d/linux_spi_test.c)
@@ -954,6 +959,10 @@ override LDFLAGS += -lrt
 endif
 endif
 
+ifeq ($(HAS_STRNLEN), yes)
+override CFLAGS  += -D'HAVE_STRNLEN=1'
+endif
+
 ifeq ($(HAS_GETOPT), yes)
 override CFLAGS  += -D'HAVE_GETOPT_H=1'
 endif
@@ -962,7 +971,11 @@ ifeq ($(HAS_PCIUTILS), yes)
 override CFLAGS  += -D'HAVE_PCIUTILS_PCI_H=1'
 endif
 
-OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)
+override LDFLAGS += $(EXTRA_LIBS)
+
+CROS_OBJS = power.o action_descriptor.o flashchips_crosbl.o cros_ec.o big_lock.o file_lock.o
+
+OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS) $(CROS_OBJS)
 
 ifeq ($(HAS_SPHINXBUILD), yes)
 override CONFIG_SPHINXBUILD_VERSION := $(shell $(SPHINXBUILD) --version | cut -d' ' -f2 )
@@ -1024,6 +1037,7 @@ config:
 	@echo "Checking for header \"sys/utsname.h\": $(HAS_UTSNAME)"
 	@echo "Checking for header \"pciutils/pci.h\": $(HAS_PCIUTILS)"
 	@echo "Checking for function \"clock_gettime\": $(HAS_CLOCK_GETTIME)"
+	@echo "Checking for function \"strnlen\": $(HAS_STRNLEN)"
 	@echo "Checking for external \"librt\": $(HAS_EXTERN_LIBRT)"
 	@if ! [ "$(PROGRAMMER_OBJS)" ]; then					\
 		echo "You have to enable at least one programmer driver!";	\
diff --git a/Makefile.d/strnlen_test.c b/Makefile.d/strnlen_test.c
new file mode 100644
index 00000000..cbca6899
--- /dev/null
+++ b/Makefile.d/strnlen_test.c
@@ -0,0 +1,9 @@
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+	(void)argc;
+	(void)argv;
+	(void)strnlen("", 0);
+	return 0;
+}
diff --git a/meson.build b/meson.build
index b1b26881..ab44a080 100644
--- a/meson.build
+++ b/meson.build
@@ -160,7 +160,6 @@ group_pci    = get_option('programmer').contains('group_pci')
 group_usb    = get_option('programmer').contains('group_usb')
 group_i2c    = get_option('programmer').contains('group_i2c')
 group_serial = get_option('programmer').contains('group_serial')
-group_jlink  = get_option('programmer').contains('group_jlink')
 group_internal = get_option('programmer').contains('group_internal')
 group_external = get_option('programmer').contains('group_external')
 
@@ -168,7 +167,6 @@ libpci     = dependency('libpci', required : group_pci, version : '>=2.2.0',
   static : (host_machine.system() == 'openbsd' ? true : false)) # On openbsd a static version of libpci is needed to get also -libz
 libusb1    = dependency('libusb-1.0', required : group_usb)
 libftdi1   = dependency('libftdi1', required : group_ftdi)
-libjaylink = dependency('libjaylink', required : group_jlink, version : '>=0.3.0')
 
 if host_machine.system() == 'windows'
   # Specifying an include_path that doesn't exist is an error,
@@ -366,12 +364,6 @@ programmer = {
     'srcs'    : files('it8212.c', 'pcidev.c'),
     'flags'   : [ '-DCONFIG_IT8212=1' ],
   },
-  'jlink_spi' : {
-    'deps'    : [ libjaylink ],
-    'groups'  : [ group_jlink, group_external ],
-    'srcs'    : files('jlink_spi.c'),
-    'flags'   : [ '-DCONFIG_JLINK_SPI=1' ],
-  },
   'linux_mtd' : {
     'systems' : [ 'linux' ],
     'deps'    : [ linux_headers ],
