diff --git a/boards/build/ESPlay.bin b/boards/build/ESPlay.bin index a1b5f9d7..90acb57b 100644 Binary files a/boards/build/ESPlay.bin and b/boards/build/ESPlay.bin differ diff --git a/boards/build/lolin32oled.bin b/boards/build/lolin32oled.bin index a27fb0ab..de74065f 100644 Binary files a/boards/build/lolin32oled.bin and b/boards/build/lolin32oled.bin differ diff --git a/boards/build/lolin32oled.zip b/boards/build/lolin32oled.zip deleted file mode 100644 index 8ada4b87..00000000 Binary files a/boards/build/lolin32oled.zip and /dev/null differ diff --git a/boards/build/lolin32oled_V02.bin b/boards/build/lolin32oled_V02.bin index c76cfd9a..082cbe82 100644 Binary files a/boards/build/lolin32oled_V02.bin and b/boards/build/lolin32oled_V02.bin differ diff --git a/boards/build/lolin32pro.bin b/boards/build/lolin32pro.bin index bb5dfc7c..bb84f938 100644 Binary files a/boards/build/lolin32pro.bin and b/boards/build/lolin32pro.bin differ diff --git a/boards/build/lolin32prostvol.bin b/boards/build/lolin32prostvol.bin index f1db5beb..2bdce05d 100644 Binary files a/boards/build/lolin32prostvol.bin and b/boards/build/lolin32prostvol.bin differ diff --git a/boards/build/malikli.bin b/boards/build/malikli.bin index a9f09989..9b9afbcc 100644 Binary files a/boards/build/malikli.bin and b/boards/build/malikli.bin differ diff --git a/boards/build/malikli.zip b/boards/build/malikli.zip deleted file mode 100644 index 3ccb4fe5..00000000 Binary files a/boards/build/malikli.zip and /dev/null differ diff --git a/boards/build/new_psram.bin b/boards/build/new_psram.bin index 19bfcccf..e7a1f891 100644 Binary files a/boards/build/new_psram.bin and b/boards/build/new_psram.bin differ diff --git a/boards/build/obsidian_psram.bin b/boards/build/obsidian_psram.bin index 6ef740ff..27345938 100644 Binary files a/boards/build/obsidian_psram.bin and b/boards/build/obsidian_psram.bin differ diff --git a/boards/build/odroid-go.bin b/boards/build/odroid-go.bin index 6302a05a..67150f65 100644 Binary files a/boards/build/odroid-go.bin and b/boards/build/odroid-go.bin differ diff --git a/boards/build/pattern.bin b/boards/build/pattern.bin index 7122f2cc..e93a63bf 100644 Binary files a/boards/build/pattern.bin and b/boards/build/pattern.bin differ diff --git a/boards/build/pcm_psram.bin b/boards/build/pcm_psram.bin index 68ab43e7..9b6830ff 100644 Binary files a/boards/build/pcm_psram.bin and b/boards/build/pcm_psram.bin differ diff --git a/boards/build/standard_adb.bin b/boards/build/standard_adb.bin index b4649796..2035d68a 100644 Binary files a/boards/build/standard_adb.bin and b/boards/build/standard_adb.bin differ diff --git a/boards/build/standard_adbnoled.bin b/boards/build/standard_adbnoled.bin index c1163398..a3bad9d6 100644 Binary files a/boards/build/standard_adbnoled.bin and b/boards/build/standard_adbnoled.bin differ diff --git a/boards/build/standard_adbnoled.zip b/boards/build/standard_adbnoled.zip deleted file mode 100644 index 3e727c82..00000000 Binary files a/boards/build/standard_adbnoled.zip and /dev/null differ diff --git a/boards/build/standard_minimal.bin b/boards/build/standard_minimal.bin index e15cdc5f..fe8cc863 100644 Binary files a/boards/build/standard_minimal.bin and b/boards/build/standard_minimal.bin differ diff --git a/boards/build/standard_psram.bin b/boards/build/standard_psram.bin index a985df51..fa7505bb 100644 Binary files a/boards/build/standard_psram.bin and b/boards/build/standard_psram.bin differ diff --git a/boards/build/standard_touch.bin b/boards/build/standard_touch.bin index 61a9d1c9..a9e69eca 100644 Binary files a/boards/build/standard_touch.bin and b/boards/build/standard_touch.bin differ diff --git a/boards/build/ttgolora1-6.bin b/boards/build/ttgolora1-6.bin index 5068a9c3..ab6d32f7 100644 Binary files a/boards/build/ttgolora1-6.bin and b/boards/build/ttgolora1-6.bin differ diff --git a/boards/build/ttgot8.bin b/boards/build/ttgot8.bin index 1bd5bb9a..6df90a0f 100644 Binary files a/boards/build/ttgot8.bin and b/boards/build/ttgot8.bin differ diff --git a/boards/build/ttgot8Vassilis.bin b/boards/build/ttgot8Vassilis.bin new file mode 100644 index 00000000..6df90a0f Binary files /dev/null and b/boards/build/ttgot8Vassilis.bin differ diff --git a/boards/build/ttgot8_Bazooka07.bin b/boards/build/ttgot8_Bazooka07.bin new file mode 100644 index 00000000..737823c1 Binary files /dev/null and b/boards/build/ttgot8_Bazooka07.bin differ diff --git a/boards/build/ttgotm.bin b/boards/build/ttgotm.bin index e456bf98..30e83c49 100644 Binary files a/boards/build/ttgotm.bin and b/boards/build/ttgotm.bin differ diff --git a/boards/build/ttgots.bin b/boards/build/ttgots.bin deleted file mode 100644 index 99b2a21a..00000000 Binary files a/boards/build/ttgots.bin and /dev/null differ diff --git a/boards/build/ttgov4.bin b/boards/build/ttgov4.bin index aa8660d9..85500295 100644 Binary files a/boards/build/ttgov4.bin and b/boards/build/ttgov4.bin differ diff --git a/boards/nvs_partition_gen.py b/boards/nvs_partition_gen.py new file mode 100644 index 00000000..40159cd8 --- /dev/null +++ b/boards/nvs_partition_gen.py @@ -0,0 +1,831 @@ +#!/usr/bin/env python +# +# esp-idf NVS partition generation tool. Tool helps in generating NVS-compatible +# partition binary, with key-value pair entries provided via a CSV file. +# +# Copyright 2018 Espressif Systems (Shanghai) PTE LTD +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from __future__ import division, print_function +from builtins import int, range, bytes +from io import open +import sys +import argparse +import binascii +import random +import struct +import os +import array +import csv +import zlib +import codecs +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from cryptography.hazmat.backends import default_backend + +VERSION1_PRINT = "v1 - Multipage Blob Support Disabled" +VERSION2_PRINT = "v2 - Multipage Blob Support Enabled" + + +""" Class for standard NVS page structure """ +class Page(object): + PAGE_PARAMS = { + "max_size": 4096, + "max_old_blob_size": 1984, + "max_new_blob_size": 4000, + "max_entries": 126 + } + + # Item type codes + U8 = 0x01 + I8 = 0x11 + U16 = 0x02 + I16 = 0x12 + U32 = 0x04 + I32 = 0x14 + SZ = 0x21 + BLOB = 0x41 + BLOB_DATA = 0x42 + BLOB_IDX = 0x48 + + # Few Page constants + HEADER_SIZE = 32 + BITMAPARRAY_OFFSET = 32 + BITMAPARRAY_SIZE_IN_BYTES = 32 + FIRST_ENTRY_OFFSET = 64 + SINGLE_ENTRY_SIZE = 32 + CHUNK_ANY = 0xFF + ACTIVE = 0xFFFFFFFE + FULL = 0xFFFFFFFC + VERSION1=0xFF + VERSION2=0xFE + + def __init__(self, page_num, is_rsrv_page=False): + self.entry_num = 0 + self.is_encrypt = False + self.encr_key = None + self.bitmap_array = array.array('B') + self.version = Page.VERSION2 + self.page_buf = bytearray(b'\xff')*Page.PAGE_PARAMS["max_size"] + if not is_rsrv_page: + self.bitmap_array = self.create_bitmap_array() + self.set_header(page_num) + + def set_header(self, page_num): + global page_header + + # set page state to active + page_header= bytearray(b'\xff') *32 + page_state_active_seq = Page.ACTIVE + struct.pack_into(' 2: + if not addr_len % 2: + addr_tmp = addr + tweak_tmp = self.reverse_hexbytes(addr_tmp) + tweak_val = tweak_tmp + (init_tweak_val * (tweak_len_needed - (len(tweak_tmp)))) + else: + addr_tmp = init_tweak_val + addr + tweak_tmp = self.reverse_hexbytes(addr_tmp) + tweak_val = tweak_tmp + (init_tweak_val * (tweak_len_needed - (len(tweak_tmp)))) + else: + tweak_val = addr + (init_tweak_val * (tweak_len_needed - len(addr))) + + # Encrypt data + data_bytes = data_input[start_idx:end_idx] + if type(data_bytes) == bytes: + data_bytes = data_bytes.decode() + + data_val = data_bytes + (init_data_val * (data_len_needed - len(data_bytes))) + encr_data_ret = self.encrypt_entry(data_val, tweak_val, encr_key_input) + encr_data_to_write = encr_data_to_write + encr_data_ret + # Update values for encrypting next set of data bytes + start_idx = end_idx + end_idx = start_idx + 64 + entry_no += 1 + + return encr_data_to_write + + + def write_entry_to_buf(self, data, entrycount,nvs_obj): + encr_data = bytearray() + + if self.is_encrypt: + encr_data_ret = self.encrypt_data(data, entrycount,nvs_obj) + encr_data[0:len(encr_data_ret)] = encr_data_ret + data = encr_data + + data_offset = Page.FIRST_ENTRY_OFFSET + (Page.SINGLE_ENTRY_SIZE * self.entry_num) + start_idx = data_offset + end_idx = data_offset + len(data) + self.page_buf[start_idx:end_idx] = data + + # Set bitmap array for entries in current page + for i in range(0, entrycount): + self.write_bitmaparray() + self.entry_num += 1 + + + def set_crc_header(self, entry_struct): + crc_data = bytearray(b'28') + crc_data[0:4] = entry_struct[0:4] + crc_data[4:28] = entry_struct[8:32] + crc_data = bytes(crc_data) + crc = zlib.crc32(crc_data, 0xFFFFFFFF) + struct.pack_into('=0, "Page overflow!!" + + # Split the binary data into two and store a chunk of available size onto curr page + if tailroom < remaining_size: + chunk_size = tailroom + else: + chunk_size = remaining_size + + remaining_size = remaining_size - chunk_size + + # Change type of data to BLOB_DATA + entry_struct[1] = Page.BLOB_DATA + + # Calculate no. of entries data chunk will require + datachunk_rounded_size = (chunk_size + 31) & ~31 + datachunk_entry_count = datachunk_rounded_size // 32 + datachunk_total_entry_count = datachunk_entry_count + 1 # +1 for the entry header + + # Set Span + entry_struct[2] = datachunk_total_entry_count + + # Update the chunkIndex + chunk_index = chunk_start + chunk_count + entry_struct[3] = chunk_index + + # Set data chunk + data_chunk = data[offset:offset + chunk_size] + + # Compute CRC of data chunk + struct.pack_into(' Page.PAGE_PARAMS["max_old_blob_size"]: + raise InputError("Version %s\n%s: Size exceeds max allowed length." % (VERSION1_PRINT,key)) + + if version == Page.VERSION2: + if encoding == "string": + if datalen > Page.PAGE_PARAMS["max_new_blob_size"]: + raise InputError("Version %s\n%s: Size exceeds max allowed length." % (VERSION2_PRINT,key)) + + # Calculate no. of entries data will require + rounded_size = (datalen + 31) & ~31 + data_entry_count = rounded_size // 32 + total_entry_count = data_entry_count + 1 # +1 for the entry header + + # Check if page is already full and new page is needed to be created right away + if encoding == "string": + if (self.entry_num + total_entry_count) >= Page.PAGE_PARAMS["max_entries"]: + raise PageFullError() + + # Entry header + entry_struct = bytearray(b'\xff')*32 + # Set Namespace Index + entry_struct[0] = ns_index + # Set Span + if version == Page.VERSION2: + if encoding == "string": + entry_struct[2] = data_entry_count + 1 + # Set Chunk Index + chunk_index = Page.CHUNK_ANY + entry_struct[3] = chunk_index + else: + entry_struct[2] = data_entry_count + 1 + + # set key + key_array = b'\x00' * 16 + entry_struct[8:24] = key_array + entry_struct[8:8 + len(key)] = key.encode() + + # set Type + if encoding == "string": + entry_struct[1] = Page.SZ + elif encoding in ["hex2bin", "binary", "base64"]: + entry_struct[1] = Page.BLOB + + if version == Page.VERSION2 and (encoding in ["hex2bin", "binary", "base64"]): + entry_struct = self.write_varlen_binary_data(entry_struct,ns_index,key,data,\ + datalen,total_entry_count, encoding, nvs_obj) + else: + self.write_single_page_entry(entry_struct, data, datalen, data_entry_count, nvs_obj) + + + + """ Low-level function to write data of primitive type into page buffer. """ + def write_primitive_data(self, key, data, encoding, ns_index,nvs_obj): + # Check if entry exceeds max number of entries allowed per page + if self.entry_num >= Page.PAGE_PARAMS["max_entries"]: + raise PageFullError() + + entry_struct = bytearray(b'\xff')*32 + entry_struct[0] = ns_index # namespace index + entry_struct[2] = 0x01 # Span + chunk_index = Page.CHUNK_ANY + entry_struct[3] = chunk_index + + # write key + key_array = b'\x00' *16 + entry_struct[8:24] = key_array + entry_struct[8:8 + len(key)] = key.encode() + + if encoding == "u8": + entry_struct[1] = Page.U8 + struct.pack_into('