[Feature]add MT2731_MP2_MR2_SVN388 baseline version

Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bsp/lk/include/lib/aes.h b/src/bsp/lk/include/lib/aes.h
new file mode 100644
index 0000000..85c0c51
--- /dev/null
+++ b/src/bsp/lk/include/lib/aes.h
@@ -0,0 +1,51 @@
+/* aes.h 
+ * Jason E. Holt
+ * released into the public domain
+ */
+
+#ifndef AES_H
+#define AES_H
+
+#include <stdint.h>
+
+enum AES_KEYSIZE {
+    AES_KEYSIZE_128 = 0,
+    AES_KEYSIZE_192,
+    AES_KEYSIZE_256
+};
+
+#if HW_AES_IMPL
+
+// XXX get from a better source?
+typedef struct {
+    enum AES_KEYSIZE size;
+    uint8_t key[256/8];
+} AES_KEY;
+
+#else // software implementation
+
+struct aes_key_struct_sw {
+    unsigned long rd_key[60];
+    int rounds;
+};
+
+typedef struct aes_key_struct_sw AES_KEY;
+
+#endif
+
+#define AES_BLOCK_SIZE 16
+
+int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
+                            AES_KEY *key);
+
+int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
+                             AES_KEY *key);
+
+void AES_decrypt(const unsigned char *in, unsigned char *out,
+                         const AES_KEY *key);
+
+void AES_encrypt(const unsigned char *in, unsigned char *out,
+                         const AES_KEY *key);
+
+
+#endif
diff --git a/src/bsp/lk/include/lib/bytes.h b/src/bsp/lk/include/lib/bytes.h
new file mode 100644
index 0000000..45e5583
--- /dev/null
+++ b/src/bsp/lk/include/lib/bytes.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2013 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __BYTES_H
+#define __BYTES_H
+
+#include <endian.h>
+#include <stdint.h>
+
+#if BYTE_ORDER == BIG_ENDIAN
+#define bytes_read_u16(x)       bytes_read_u16_be(x)
+#define bytes_read_u24(x)       bytes_read_u24_be(x)
+#define bytes_read_u32(x)       bytes_read_u32_be(x)
+#define bytes_write_u16(x, y)   bytes_write_u16_be(x, y)
+#define bytes_write_u24(x, y)   bytes_write_u24_be(x, y)
+#define bytes_write_u32(x, y)   bytes_write_u32_be(x, y)
+#elif BYTE_ORDER == LITTLE_ENDIAN
+#define bytes_read_u16(x)       bytes_read_u16_le(x)
+#define bytes_read_u24(x)       bytes_read_u24_le(x)
+#define bytes_read_u32(x)       bytes_read_u32_le(x)
+#define bytes_write_u16(x, y)   bytes_write_u16_le(x, y)
+#define bytes_write_u24(x, y)   bytes_write_u24_le(x, y)
+#define bytes_write_u32(x, y)   bytes_write_u32_le(x, y)
+#else
+#error "Endianness not defined!"
+#endif
+
+
+// Big endian interfaces
+uint16_t bytes_read_u16_be(const uint8_t *buf);
+uint32_t bytes_read_u24_be(const uint8_t *buf);
+uint32_t bytes_read_u32_be(const uint8_t *buf);
+
+uint8_t* bytes_write_u16_be(uint8_t *buf, uint16_t val);
+uint8_t* bytes_write_u24_be(uint8_t *buf, uint32_t val);
+uint8_t* bytes_write_u32_be(uint8_t *buf, uint32_t val);
+
+// Little endian interfaces
+uint16_t bytes_read_u16_le(const uint8_t *buf);
+uint32_t bytes_read_u24_le(const uint8_t *buf);
+uint32_t bytes_read_u32_le(const uint8_t *buf);
+
+uint8_t* bytes_write_u16_le(uint8_t *buf, uint16_t val);
+uint8_t* bytes_write_u24_le(uint8_t *buf, uint32_t val);
+uint8_t* bytes_write_u32_le(uint8_t *buf, uint32_t val);
+
+// Bit swapping interfaces
+uint8_t  bytes_swap_bits_u8(uint8_t val);
+uint16_t bytes_swap_bits_u16(uint16_t val);
+uint32_t bytes_swap_bits_u24(uint32_t val);
+uint32_t bytes_swap_bits_u32(uint32_t val);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/cksum.h b/src/bsp/lk/include/lib/cksum.h
new file mode 100644
index 0000000..130e095
--- /dev/null
+++ b/src/bsp/lk/include/lib/cksum.h
@@ -0,0 +1,32 @@
+#ifndef __CKSUM_H
+#define __CKSUM_H
+
+#include <compiler.h>
+
+__BEGIN_CDECLS
+
+ /*
+  * Computes the CRC-CCITT, starting with an initialization value.
+  * buf: the data on which to apply the checksum
+  * length: the number of bytes of data in 'buf' to be calculated.
+  */
+unsigned short crc16(const unsigned char *buf, unsigned int length);
+
+ /*
+  * Computes an updated version of the CRC-CCITT from existing CRC.
+  * crc: the previous values of the CRC
+  * buf: the data on which to apply the checksum
+  * length: the number of bytes of data in 'buf' to be calculated.
+  */
+unsigned short update_crc16(unsigned short crc, const unsigned char *buf, unsigned int len);
+
+unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len);
+
+unsigned long adler32(unsigned long adler, const unsigned char *buf, unsigned int len);
+
+uint32_t crc32_no_comp(uint32_t crc, const unsigned char *buf, unsigned int len);
+
+__END_CDECLS
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/console.h b/src/bsp/lk/include/lib/console.h
new file mode 100644
index 0000000..1bbe854
--- /dev/null
+++ b/src/bsp/lk/include/lib/console.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2008-2009 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_CONSOLE_H
+#define __LIB_CONSOLE_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <compiler.h>
+
+/* command args */
+typedef struct {
+	const char *str;
+	unsigned long u;
+	void* p;
+	long i;
+	bool b;
+} cmd_args;
+
+typedef int (*console_cmd)(int argc, const cmd_args *argv);
+
+#define CMD_AVAIL_NORMAL (0x1 << 0)
+#define CMD_AVAIL_PANIC  (0x1 << 1)
+#define CMD_AVAIL_ALWAYS (CMD_AVAIL_NORMAL | CMD_AVAIL_PANIC)
+
+/* a block of commands to register */
+typedef struct {
+	const char *cmd_str;
+	const char *help_str;
+	const console_cmd cmd_callback;
+	uint8_t availability_mask;
+} cmd;
+
+typedef struct _cmd_block {
+	struct _cmd_block *next;
+	size_t count;
+	const cmd *list;
+} cmd_block;
+
+/* register a static block of commands at init time */
+#if WITH_LIB_CONSOLE
+
+/* enable the panic shell if we're being built */
+#if !defined(ENABLE_PANIC_SHELL) && PLATFORM_SUPPORTS_PANIC_SHELL
+#define ENABLE_PANIC_SHELL 1
+#endif
+
+#define STATIC_COMMAND_START static const cmd _cmd_list[] = {
+
+#define STATIC_COMMAND_END(name) }; cmd_block _cmd_block_##name __ALIGNED(sizeof(void *)) __SECTION(".commands") = \
+    { NULL, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list }
+
+#define STATIC_COMMAND_START_NAMED(name) static const cmd _cmd_list_##name[] = {
+
+#define STATIC_COMMAND_END_NAMED(name) }; cmd_block _cmd_block_##name __ALIGNED(sizeof(void *)) __SECTION(".commands") = \
+    { NULL, sizeof(_cmd_list_##name) / sizeof(_cmd_list_##name[0]), _cmd_list_##name }
+
+#define STATIC_COMMAND(command_str, help_str, func) { command_str, help_str, func, CMD_AVAIL_NORMAL },
+#define STATIC_COMMAND_MASKED(command_str, help_str, func, availability_mask) { command_str, help_str, func, availability_mask },
+
+#else
+
+/* no command blocks, so null them out */
+#define STATIC_COMMAND_START
+#define STATIC_COMMAND_END(name)
+#define STATIC_COMMAND_START_NAMED(name)
+#define STATIC_COMMAND_END_NAMED(name)
+
+#define STATIC_COMMAND(command_str, help_str, func)
+
+#endif
+
+#define COMMAND_BLOCK_INIT_ITEM(cmd_block_ptr, cmd_ptr) {(cmd_block_ptr)->next = NULL; (cmd_block_ptr)->count = 1; (cmd_block_ptr)->list = cmd_ptr;}
+
+/* external api */
+int console_init(void);
+void console_start(void);
+void console_register_commands(cmd_block *block);
+int console_run_script(const char *string);
+int console_run_script_locked(const char *string); // special case from inside a command
+console_cmd console_get_command_handler(const char *command);
+void console_abort_script(void);
+
+/* panic shell api */
+void panic_shell_start(void);
+
+extern int lastresult;
+
+#endif
diff --git a/src/bsp/lk/include/lib/dpc.h b/src/bsp/lk/include/lib/dpc.h
new file mode 100644
index 0000000..36fcb53
--- /dev/null
+++ b/src/bsp/lk/include/lib/dpc.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2008 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __KERNEL_DPC_H
+#define __KERNEL_DPC_H
+
+#include <list.h>
+#include <sys/types.h>
+
+typedef void (*dpc_callback)(void *arg);
+
+#define DPC_FLAG_NORESCHED 0x1
+
+status_t dpc_queue(dpc_callback, void *arg, uint flags);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/evlog.h b/src/bsp/lk/include/lib/evlog.h
new file mode 100644
index 0000000..53f50e4
--- /dev/null
+++ b/src/bsp/lk/include/lib/evlog.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_EVLOG_H
+#define __LIB_EVLOG_H
+
+#include <inttypes.h>
+#include <sys/types.h>
+
+typedef struct evlog {
+	uint head;
+	uint unitsize;
+	uint len_pow2;
+	uintptr_t *items;
+} evlog_t;
+
+status_t evlog_init_etc(evlog_t *e, uint len, uint unitsize, uintptr_t *items);
+status_t evlog_init(evlog_t *e, uint len, uint unitsize);
+
+/* callback to evlog_dump. */
+typedef void (*evlog_dump_cb)(const uintptr_t *);
+
+void evlog_dump(evlog_t *e, evlog_dump_cb cb);
+
+/* bump the head pointer and return the old one.
+ */
+uint evlog_bump_head(evlog_t *e);
+
+/*
+ * It's assumed you're following a pattern similar to the following:
+ *
+void evlog_add2(evlog_t *e, uintptr_t a, uintptr_t b)
+{
+	uint index = evlog_bump_head(e);
+
+	e->items[index] = a;
+	e->items[index + 1] = b;
+}
+*/
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/font.h b/src/bsp/lk/include/lib/font.h
new file mode 100644
index 0000000..288d984
--- /dev/null
+++ b/src/bsp/lk/include/lib/font.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_FONT_H
+#define __LIB_FONT_H
+
+#include <lib/gfx.h>
+
+#define FONT_X  6
+#define FONT_Y  12
+
+void font_draw_char(gfx_surface *surface, unsigned char c, int x, int y, uint32_t color);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/gfx.h b/src/bsp/lk/include/lib/gfx.h
new file mode 100644
index 0000000..8c68daa
--- /dev/null
+++ b/src/bsp/lk/include/lib/gfx.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_GFX_H
+#define __LIB_GFX_H
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <inttypes.h>
+
+// gfx library
+
+// different graphics formats
+typedef enum {
+    GFX_FORMAT_NONE,
+    GFX_FORMAT_RGB_565,
+    GFX_FORMAT_RGB_332,
+    GFX_FORMAT_RGB_2220,
+    GFX_FORMAT_ARGB_8888,
+    GFX_FORMAT_RGB_x888,
+    GFX_FORMAT_MONO,
+
+    GFX_FORMAT_MAX
+} gfx_format;
+
+#define MAX_ALPHA 255
+
+/**
+ * @brief  Describe a graphics drawing surface
+ *
+ * The gfx_surface object represents a framebuffer that can be rendered
+ * to.  Elements include a pointer to the actual pixel memory, its size, its
+ * layout, and pointers to basic drawing functions.
+ *
+ * @ingroup graphics
+ */
+typedef struct gfx_surface {
+    void *ptr;
+    bool free_on_destroy;
+    gfx_format format;
+    uint width;
+    uint height;
+    uint stride;
+    uint pixelsize;
+    size_t len;
+    uint alpha;
+
+    // function pointers
+    uint32_t (*translate_color)(uint32_t input);
+    void (*copyrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint x2, uint y2);
+    void (*fillrect)(struct gfx_surface *, uint x, uint y, uint width, uint height, uint color);
+    void (*putpixel)(struct gfx_surface *, uint x, uint y, uint color);
+    void (*flush)(uint starty, uint endy);
+} gfx_surface;
+
+// copy a rect from x,y with width x height to x2, y2
+void gfx_copyrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint x2, uint y2);
+
+// fill a rect within the surface with a color
+void gfx_fillrect(gfx_surface *surface, uint x, uint y, uint width, uint height, uint color);
+
+// draw a pixel at x, y in the surface
+void gfx_putpixel(gfx_surface *surface, uint x, uint y, uint color);
+
+// draw a single pixel line between x1,y1 and x2,y1
+void gfx_line(gfx_surface *surface, uint x1, uint y1, uint x2, uint y2, uint color);
+
+// clear the entire surface with a color
+static inline void gfx_clear(gfx_surface *surface, uint color)
+{
+    surface->fillrect(surface, 0, 0, surface->width, surface->height, color);
+
+    if (surface->flush)
+        surface->flush(0, surface->height-1);
+}
+
+// blend between two surfaces
+void gfx_surface_blend(struct gfx_surface *target, struct gfx_surface *source, uint destx, uint desty);
+
+void gfx_flush(struct gfx_surface *surface);
+
+void gfx_flush_rows(struct gfx_surface *surface, uint start, uint end);
+
+// surface setup
+gfx_surface *gfx_create_surface(void *ptr, uint width, uint height, uint stride, gfx_format format);
+
+// utility routine to make a surface out of a display info
+struct display_info;
+gfx_surface *gfx_create_surface_from_display(struct display_info *);
+
+// free the surface
+// optionally frees the buffer if the free bit is set
+void gfx_surface_destroy(struct gfx_surface *surface);
+
+// utility routine to fill the display with a little moire pattern
+void gfx_draw_pattern(void);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/gfxconsole.h b/src/bsp/lk/include/lib/gfxconsole.h
new file mode 100644
index 0000000..5a85b07
--- /dev/null
+++ b/src/bsp/lk/include/lib/gfxconsole.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_GFXCONSOLE_H
+#define __LIB_GFXCONSOLE_H
+
+#include <lib/gfx.h>
+
+void gfxconsole_start_on_display(void);
+void gfxconsole_start(gfx_surface *surface);
+
+#endif
+
diff --git a/src/bsp/lk/include/lib/nftl.h b/src/bsp/lk/include/lib/nftl.h
new file mode 100644
index 0000000..735e96b
--- /dev/null
+++ b/src/bsp/lk/include/lib/nftl.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018 MediaTek Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <list.h>
+#include <sys/types.h>
+
+struct nftl_info {
+    char *name;
+    char *label;
+    u64 total_size;
+    u32 erase_size;
+    u32 write_size;
+
+    int (*block_isbad)(struct nftl_info *info, u32 page);
+    ssize_t (*erase)(struct nftl_info *info, off_t offset, ssize_t len);
+    ssize_t (*read)(struct nftl_info *info, void *buf, off_t offset,
+                    ssize_t len);
+    ssize_t (*write)(struct nftl_info *info, const void *buf, off_t offset,
+                     ssize_t len);
+    int (*ioctl)(struct nftl_info *info, int request, void *argp);
+};
+
+int nftl_mount_bdev(struct nftl_info *info);
+struct nftl_info *nftl_search_by_address(u64 address, u64 *start);
+struct nftl_info *nftl_open(const char *name);
+void nftl_close(struct nftl_info *info);
+int nftl_add_part(const char *main_part, const char *sub_part,
+                  const char *sub_label, u64 offset, u64 len);
+struct nftl_info *nftl_add_master(const char *name);
+int nftl_delete_part(const char *name);
+void nftl_dump_parts(void);
+int nftl_block_mapping(struct nftl_info *info, u32 *page);
+int nftl_block_isbad(struct nftl_info *info, u32 page);
+ssize_t nftl_erase(struct nftl_info *info, off_t offset, ssize_t len);
+ssize_t nftl_read(struct nftl_info *info, void *buf, off_t offset, ssize_t len);
+ssize_t nftl_write(struct nftl_info *info, const void *buf, off_t offset,
+                   ssize_t len);
diff --git a/src/bsp/lk/include/lib/page_alloc.h b/src/bsp/lk/include/lib/page_alloc.h
new file mode 100644
index 0000000..858d83f
--- /dev/null
+++ b/src/bsp/lk/include/lib/page_alloc.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 Google, Inc. All rights reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_PAGE_ALLOC_H
+#define __LIB_PAGE_ALLOC_H
+
+#include <stddef.h>
+#include <sys/types.h>
+#include <compiler.h>
+
+// to pick up PAGE_SIZE, PAGE_ALIGN, etc
+#if WITH_KERNEL_VM
+#include <kernel/vm.h>
+#else
+#include <kernel/novm.h>
+#endif
+
+/* A simple page-aligned wrapper around the pmm or novm implementation of
+ * the underlying physical page allocator. Used by system heaps or any
+ * other user that wants pages of memory but doesn't want to use LK
+ * specific apis.
+ */
+
+__BEGIN_CDECLS;
+
+void *page_alloc(size_t pages);
+void page_free(void *ptr, size_t pages);
+
+// You can call this once at the start, and it will either return a page or it
+// will return some non-page-aligned memory that would otherwise go to waste.
+void *page_first_alloc(size_t *size_return);
+
+__END_CDECLS;
+
+#endif
diff --git a/src/bsp/lk/include/lib/partition.h b/src/bsp/lk/include/lib/partition.h
new file mode 100644
index 0000000..cc6b0a9
--- /dev/null
+++ b/src/bsp/lk/include/lib/partition.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2009 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_PARTITION_H
+#define __LIB_PARTITION_H
+
+#include <sys/types.h>
+
+/* examine and try to publish partitions on a particular device at a particular offset */
+int partition_publish(const char *device, off_t offset);
+
+/* remove any published subdevices on this device */
+int partition_unpublish(const char *device);
+
+/* update partition table on a particular device at a particular offset */
+int partition_update(const char *device, off_t offset, const char *data, size_t sz);
+#endif
+
diff --git a/src/bsp/lk/include/lib/ptable.h b/src/bsp/lk/include/lib/ptable.h
new file mode 100644
index 0000000..79a4fd0
--- /dev/null
+++ b/src/bsp/lk/include/lib/ptable.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, Google, Inc. All rights reserved
+ * Copyright (c) 2014, Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <compiler.h>
+#include <sys/types.h>
+#include <lib/bio.h>
+
+#define MAX_FLASH_PTABLE_NAME_LEN 12
+#define FLASH_PTABLE_ALLOC_END 0x1
+
+struct ptable_entry {
+    uint64_t offset;
+    uint64_t length;
+    uint32_t flags;
+    uint8_t name[MAX_FLASH_PTABLE_NAME_LEN];
+};
+
+bool     ptable_found_valid(void);
+bdev_t*  ptable_get_device(void);
+status_t ptable_scan(const char* bdev_name, uint64_t offset);
+status_t ptable_find(const char *name, struct ptable_entry *entry) __NONNULL((1));
+status_t ptable_create_default(const char* bdev_name, uint64_t offset) __NONNULL();
+status_t ptable_add(const char *name, uint64_t min_len, uint32_t flags) __NONNULL();
+status_t ptable_remove(const char *name) __NONNULL();
+void     ptable_dump(void);
diff --git a/src/bsp/lk/include/lib/sysparam.h b/src/bsp/lk/include/lib/sysparam.h
new file mode 100644
index 0000000..4841a21
--- /dev/null
+++ b/src/bsp/lk/include/lib/sysparam.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013, Google, Inc. All rights reserved
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#pragma once
+
+#include <stdbool.h>
+#include <sys/types.h>
+#include <lib/bio.h>
+
+#ifndef SYSPARAM_ALLOW_WRITE
+#define SYSPARAM_ALLOW_WRITE 0
+#endif
+
+status_t sysparam_scan(bdev_t *bdev, off_t offset, size_t len);
+status_t sysparam_reload(void);
+
+void sysparam_dump(bool show_all);
+
+ssize_t sysparam_length(const char *name);
+ssize_t sysparam_read(const char *name, void *data, size_t len);
+status_t sysparam_get_ptr(const char *name, const void **ptr, size_t *len);
+
+#if SYSPARAM_ALLOW_WRITE
+status_t sysparam_add(const char *name, const void *value, size_t len);
+status_t sysparam_remove(const char *name);
+status_t sysparam_lock(const char *name);
+status_t sysparam_write(void);
+#endif
+
diff --git a/src/bsp/lk/include/lib/text.h b/src/bsp/lk/include/lib/text.h
new file mode 100644
index 0000000..02ed823
--- /dev/null
+++ b/src/bsp/lk/include/lib/text.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __LIB_TEXT_H
+#define __LIB_TEXT_H
+
+#include <lib/font.h>
+
+/* super cheezy mechanism to stick lines of text up on top of whatever is being drawn */
+/* XXX replace with something more generic later */
+void text_draw(int x, int y, const char *string);
+
+/* super dumb, someone has to call this to refresh everything */
+void text_update(void);
+
+#endif
+