Skip to content

Commit

Permalink
Update RAK4631 bootloader to V0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
beegee-tokyo committed May 20, 2023
1 parent 0477181 commit adbeffe
Show file tree
Hide file tree
Showing 1,696 changed files with 1,010,224 additions and 23 deletions.
File renamed without changes.
16 changes: 11 additions & 5 deletions bootloader/RAK4630/Latest/WisCore_RAK4631_Bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ MBR_HEX = lib/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex
# linker by MCU eg. nrf52840.ld
LD_FILE = linker/$(MCU_SUB_VARIANT).ld

# Modify software version to 0.4.2.Add by Michael.
# Modify software version to 0.4.3.Add by Michael.
# This version is based on Adafruit_nRF52_Bootloader 0.6.2-11 modification.
# GIT_VERSION := $(shell git describe --dirty --always --tags)
GIT_VERSION := 0.4.2
GIT_VERSION := 0.4.3
GIT_SUBMODULE_VERSIONS := $(shell git submodule status | cut -d" " -f3,4 | paste -s -d" " -)

# compiled file name
Expand Down Expand Up @@ -60,7 +60,7 @@ RM = rm -rf
CP = cp

# Flasher utility options
NRFUTIL = adafruit-nrfutil
NRFUTIL = ./adafruit-nrfutil.exe
NRFJPROG = nrfjprog
FLASHER ?= nrfjprog
PYOCD ?= pyocd
Expand Down Expand Up @@ -258,7 +258,6 @@ CFLAGS += \
-fdata-sections \
-fno-builtin \
-fshort-enums \
-fstack-usage \
-fno-strict-aliasing \
-Wall \
-Wextra \
Expand All @@ -275,6 +274,8 @@ CFLAGS += \
-Wunreachable-code \
-ggdb

# -fstack-usage \
# Suppress warning caused by SDK
CFLAGS += -Wno-unused-parameter -Wno-expansion-to-defined

Expand Down Expand Up @@ -303,7 +304,8 @@ ifneq ($(USE_NFCT),yes)
endif

CFLAGS += -DSOFTDEVICE_PRESENT
CFLAGS += -DUF2_VERSION='"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS)"'
CFLAGS += -DUF2_VERSION='"0.4.3"'
#'"$(GIT_VERSION) $(GIT_SUBMODULE_VERSIONS)"'
CFLAGS += -DBLEDIS_FW_VERSION='"$(GIT_VERSION) $(SD_NAME) $(SD_VERSION)"'

_VER = $(subst ., ,$(word 1, $(subst -, ,$(GIT_VERSION))))
Expand Down Expand Up @@ -361,6 +363,10 @@ INC_PATHS = $(addprefix -I,$(IPATH))
# default target to build
all: $(BUILD)/$(OUT_NAME).out $(BUILD)/$(OUT_NAME)_nosd.hex $(BUILD)/update-$(OUT_NAME)_nosd.uf2 $(BUILD)/$(MERGED_FILE).hex $(BUILD)/$(MERGED_FILE).zip

zip:
(BUILD)/$(MERGED_FILE).zip: $(BUILD)/$(OUT_NAME).hex
@$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV) --bootloader $< --softdevice $(SD_HEX) $@

# Print out the value of a make variable.
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
Expand Down
105 changes: 105 additions & 0 deletions bootloader/RAK4630/Latest/WisCore_RAK4631_Bootloader/create_uf2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import sys
import struct

Import("env")

# Parse input and create UF2 file
def create_uf2(source, target, env):
# source_hex = target[0].get_abspath()
source_hex = target[0].get_string(False)
source_hex = '.\\'+source_hex
print("#########################################################")
print("Create UF2 from "+source_hex)
print("#########################################################")
# print("Source: " + source_hex)
target = source_hex.replace(".hex", "")
target = target + ".uf2"
# print("Target: " + target)

with open(source_hex, mode='rb') as f:
inpbuf = f.read()

outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8"))

write_file(target, outbuf)
print("#########################################################")
print(target + " is ready to flash to target device")
print("#########################################################")


# Add callback after .hex file was created
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", create_uf2)

# UF2 creation taken from uf2conv.py
UF2_MAGIC_START0 = 0x0A324655 # "UF2\n"
UF2_MAGIC_START1 = 0x9E5D5157 # Randomly selected
UF2_MAGIC_END = 0x0AB16F30 # Ditto

familyid = 0xADA52840


class Block:
def __init__(self, addr):
self.addr = addr
self.bytes = bytearray(256)

def encode(self, blockno, numblocks):
global familyid
flags = 0x0
if familyid:
flags |= 0x2000
hd = struct.pack("<IIIIIIII",
UF2_MAGIC_START0, UF2_MAGIC_START1,
flags, self.addr, 256, blockno, numblocks, familyid)
hd += self.bytes[0:256]
while len(hd) < 512 - 4:
hd += b"\x00"
hd += struct.pack("<I", UF2_MAGIC_END)
return hd


def write_file(name, buf):
with open(name, "wb") as f:
f.write(buf)
# print("Wrote %d bytes to %s." % (len(buf), name))


def convert_from_hex_to_uf2(buf):
global appstartaddr
appstartaddr = None
upper = 0
currblock = None
blocks = []
for line in buf.split('\n'):
if line[0] != ":":
continue
i = 1
rec = []
while i < len(line) - 1:
rec.append(int(line[i:i+2], 16))
i += 2
tp = rec[3]
if tp == 4:
upper = ((rec[4] << 8) | rec[5]) << 16
elif tp == 2:
upper = ((rec[4] << 8) | rec[5]) << 4
assert (upper & 0xffff) == 0
elif tp == 1:
break
elif tp == 0:
addr = upper | (rec[1] << 8) | rec[2]
if appstartaddr == None:
appstartaddr = addr
i = 4
while i < len(rec) - 1:
if not currblock or currblock.addr & ~0xff != addr & ~0xff:
currblock = Block(addr & ~0xff)
blocks.append(currblock)
currblock.bytes[addr & 0xff] = rec[i]
addr += 1
i += 1
numblocks = len(blocks)
resfile = b""
for i in range(0, numblocks):
resfile += blocks[i].encode(i, numblocks)
return resfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


#define BLEGAP_EVENT_LENGTH 6
#define BLEGATT_ATT_MTU_MAX 247
#define BLEGATT_ATT_MTU_MAX 23
enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 };

#define DFU_REV_MAJOR 0x00 /** DFU Major revision number to be exposed. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void usb_teardown(void);

// These value must be the same with one in dfu_transport_ble.c
#define BLEGAP_EVENT_LENGTH 6
#define BLEGATT_ATT_MTU_MAX 247
#define BLEGATT_ATT_MTU_MAX 23
enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 };

//--------------------------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ STATIC_ASSERT(FAT_ENTRIES_PER_SECTOR == 256); // FAT
#define STR0(x) #x
#define STR(x) STR0(x)

char infoUf2File[128*3] =
"UF2 Bootloader " UF2_VERSION "\r\n"
"Model: " UF2_PRODUCT_NAME "\r\n"
"Board-ID: " UF2_BOARD_ID "\r\n"
"Date: " __DATE__ "\r\n";
char infoUf2File[128 * 3] =
"UF2 Bootloader " UF2_VERSION "\r\n"
"Model: " UF2_PRODUCT_NAME "\r\n"
"Board-ID: " UF2_BOARD_ID "\r\n"
"Date: " __DATE__ "\r\n"
"Ver: 0.4.3\r\n";

const char indexFile[] =
"<!doctype html>\n"
Expand Down
Loading

0 comments on commit adbeffe

Please sign in to comment.