Unverified Commit 310faf7f authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Merge pull request #2886 from nodemcu/dev

Next master drop
parents 68c425c0 a08e74d9
......@@ -6,6 +6,7 @@ local/
user_config.h
server-ca.crt
luac.cross
luac.cross.int
uz_unzip
uz_zip
tools/toolchains/
......@@ -14,3 +15,7 @@ tools/toolchains/
.cproject
.project
.settings/
.vscode
#ignore temp file for build infos
buildinfo.h
#os:
# - windows
# - linux
language: cpp
matrix:
include:
- os: linux
env:
- OS="$TRAVIS_OS_NAME"
- LUACC=./luac.cross
- os: windows
env:
- MSBUILD_PATH="c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
- OS="$TRAVIS_OS_NAME"
- LUACC=msvc/luac-cross/x64/Debug/luac.cross.exe
addons:
apt:
packages:
......@@ -8,16 +24,13 @@ cache:
- directories:
- cache
script:
- export BUILD_DATE=$(date +%Y%m%d)
- make EXTRA_CCFLAGS="-DBUILD_DATE='\"'$BUILD_DATE'\"'" all
- cd bin/
- file_name_float="nodemcu_float_${TRAVIS_TAG}.bin"
- srec_cat -output ${file_name_float} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
- cd ../
- make clean
- make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL -DBUILD_DATE='\"'$BUILD_DATE'\"'"
- cd bin/
- file_name_integer="nodemcu_integer_${TRAVIS_TAG}.bin"
- srec_cat -output ${file_name_integer} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
- echo OS is $OS $TRAVIS_OS_NAME
# http://docs.travis-ci.com/user/environment-variables/#Convenience-Variables
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/pr-build.sh; fi
- if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-linux.sh; fi
- if [ "$OS" = "windows" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/ci-build-windows-ms.sh; fi
- if [ "$OS" = "linux" -a "$TRAVIS_PULL_REQUEST" != "false" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/pr-build.sh; fi
- cd "$TRAVIS_BUILD_DIR"
- echo "checking:"
- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 echo
- find lua_modules lua_examples -iname "*.lua" -print0 | xargs -0 $LUACC -p
# - if [ "$OS" = "linux" ]; then bash "$TRAVIS_BUILD_DIR"/tools/travis/run-luacheck.sh || true ; fi
......@@ -26,6 +26,13 @@ Use the platform and tools you feel most comfortable with. There are no constrai
- [Full-fledged Linux environment](http://www.esp8266.com/wiki/doku.php?id=toolchain#how_to_setup_a_vm_to_host_your_toolchain), either physical or virtual.
- [Docker image](https://hub.docker.com/r/marcelstoer/nodemcu-build/) which allows running the build inside the container as if you were running a build script on your local machine.
## Writing Lua Code
A great resource about writing Lua for NodeMCU can be found in [Lua Developer FAQ](https://nodemcu.readthedocs.io/en/latest/lua-developer-faq/) - make sure to read it! When you're writing your Lua code and it's not working as it should you can test it with `luacheck` tool that can help you find various types of bugs. To install it you have to install [luarocks](https://luarocks.org/) and use command `sudo luarocks install luacheck` to install the tool. Now you're ready to go! By using this command (assuming you're in `nodemcu-firmware` directory):
`luacheck --config tools/luacheck_config.lua <your file to check>`
you can look for bugs and problems within the code!
## Writing Documentation
The NodeMCU documentation is maintained within the same repository as the code. The primary reason is to keep the two in sync more easily. It's thus trivial for the NodeMCU team to verify that a PR includes the necessary documentation. Furthermore, the documentation is merged automatically with the code if it moves from branch X to Y.
......
......@@ -2,29 +2,42 @@
#
.NOTPARALLEL:
TOOLCHAIN_VERSION:=20181106.0
TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
# SDK base version, as released by Espressif
SDK_BASE_VER:=2.2.1
# SDK base version, as released by Espressif depends on the RELEASE flag
#
# RELEASE = lastest pulls the latest V3.0.0 branch version as at the issue of this make
# otherwise it pulls the labelled version in the SDK version's release directory
#
ifeq ("$(RELEASE)","latest-3.0")
SDK_VER := 3.0.0
SDK_FILE_SHA1 := NA
SDK_ZIP_ROOT := ESP8266_NONOS_SDK-release-v$(SDK_VER)
SDK_FILE_VER := release/v$(SDK_VER)
else ifeq ("$(RELEASE)","master")
SDK_VER := master
SDK_FILE_SHA1 := NA
SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_VER)
SDK_FILE_VER := $(SDK_VER)
else
# SDK_VER := 3.0
# SDK_FILE_VER := v$(SDK_VER)
SDK_FILE_VER := e4434aa730e78c63040ace360493aef420ec267c
SDK_VER := 3.0-e4434aa
SDK_FILE_SHA1 := ac6528a6a206d3d4c220e4035ced423eb314cfbf
SDK_ZIP_ROOT := ESP8266_NONOS_SDK-$(SDK_FILE_VER)
endif
SDK_REL_DIR := sdk/esp_iot_sdk_v$(SDK_VER)
SDK_DIR := $(TOP_DIR)/$(SDK_REL_DIR)
APP_DIR := $(TOP_DIR)/app
# no patch: SDK_VER equals SDK_BASE_VER and sdk dir depends on sdk_extracted
SDK_VER:=$(SDK_BASE_VER)
SDK_DIR_DEPENDS:=sdk_extracted
ESPTOOL_VER := 2.6
# with patch: SDK_VER differs from SDK_BASE_VER and sdk dir depends on sdk_patched
#SDK_PATCH_VER:=f8f27ce
#SDK_VER:=$(SDK_BASE_VER)-$(SDK_PATCH_VER)
#SDK_DIR_DEPENDS:=sdk_patched
# Ensure that the Espresif SDK is search before application paths and also prevent
# the SDK's c_types.h from being included from anywhere, by predefining its include-guard.
SDK_FILE_VER:=$(SDK_BASE_VER)
SDK_FILE_SHA1:=48f2242d5895823709f222bf0fffce9d525996c8
# SDK_PATCH_SHA1:=0bc21ec77b08488f04d3e1c9d161b711d07201a8
# Ensure we search "our" SDK before the tool-chain's SDK (if any)
TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SDK_REL_DIR=sdk/esp_iot_sdk_v$(SDK_VER)
SDK_DIR:=$(TOP_DIR)/$(SDK_REL_DIR)
CCFLAGS:= -I$(TOP_DIR)/sdk-overrides/include -I$(TOP_DIR)/app/include/lwip/app -I$(SDK_DIR)/include
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS)
CCFLAGS := $(CCFLAGS) -I $(PDIR)sdk-overrides/include -I $(SDK_DIR)/include -D_C_TYPES_H_
LDFLAGS := -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS)
ifdef DEBUG
CCFLAGS += -ggdb -O0
......@@ -33,19 +46,19 @@ else
CCFLAGS += -O2
endif
#Handling of V=1/VERBOSE=1 flag
# Handling of V=1/VERBOSE=1 flag
#
# if V=1, $(summary) does nothing
# if V is unset or not 1, $(summary) echoes a summary
VERBOSE ?=
V ?= $(VERBOSE)
ifeq ("$(V)","1")
export summary := @true
export summary := @true
else
export summary := @echo
# disable echoing of commands, directory names
MAKEFLAGS += --silent -w
export summary := @echo
# disable echoing of commands, directory names
MAKEFLAGS += --silent -w
endif # $(V)==1
ifndef BAUDRATE
......@@ -55,9 +68,34 @@ endif
#############################################################
# Select compile
#
ifeq ($(OS),Windows_NT)
# WIN32
# We are under windows.
# ** HEALTH WARNING ** This section is largely legacy directives left over from
# an Espressif template. As far as I (TerrryE) know, we've only used the Linux
# Path. I have successfully build AMD and Intel (both x86, AMD64) and RPi ARM6
# all under Ubuntu. Our docker container runs on Windows in an Ubuntu VM.
# Johny Mattson maintains a prebuild AMD64 xtensa cross-compile gcc v4.8.5
# toolchain which is compatible with the non-OS SDK and can be used on any recent
# Ubuntu version including the Docker and Travis build environments.
#
# You have the option to build your own toolchain and specify a TOOLCHAIN_ROOT
# environment variable (see https://github.com/pfalcon/esp-open-sdk). If your
# architecture is compatable then you can omit this variable and the make will
# download and use this prebuilt toolchain.
#
# If any developers wish to develop, test and support alternative environments
# then please raise a GitHub issue on this work.
#
ifndef $(OS)
# Assume Windows if MAKE_HOST contains "indows" and Linux otherwise
ifneq (,$(findstring indows,$(MAKE_HOST)))
OS := windows
else
OS := linux
endif
endif
ifneq (,$(findstring indows,$(OS)))
#------------ BEGIN UNTESTED ------------ We are not under Linux, e.g.under windows.
ifeq ($(XTENSA_CORE),lx106)
# It is xcc
AR = xt-ar
......@@ -91,16 +129,28 @@ ifeq ($(OS),Windows_NT)
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
# ->IA32
endif
#---------------- END UNTESTED ---------------- We are under windows.
else
# We are under other system, may be Linux. Assume using gcc.
# Can we use -fdata-sections?
PLATFORM:=linux-x86_64
# We are under other system, may be Linux. Assume using gcc.
UNAME_S := $(shell uname -s)
UNAME_P := $(shell uname -p)
ifeq ($(OS),linux)
ifndef TOOLCHAIN_ROOT
TOOLCHAIN_VERSION = 20181106.0
GCCTOOLCHAIN = linux-x86_64-$(TOOLCHAIN_VERSION)
TOOLCHAIN_ROOT = $(TOP_DIR)/tools/toolchains/esp8266-$(GCCTOOLCHAIN)
GITHUB_TOOLCHAIN = https://github.com/jmattsson/esp-toolchains
export PATH:=$(PATH):$(TOOLCHAIN_ROOT)/bin
endif
endif
ifndef COMPORT
ESPPORT = /dev/ttyUSB0
else
ESPPORT = $(COMPORT)
endif
export PATH := $(PATH):$(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/
CCFLAGS += -ffunction-sections -fno-jump-tables -fdata-sections
AR = xtensa-lx106-elf-ar
CC = $(WRAPCC) xtensa-lx106-elf-gcc
......@@ -109,35 +159,24 @@ else
CPP = $(WRAPCC) xtensa-lx106-elf-gcc -E
OBJCOPY = xtensa-lx106-elf-objcopy
FIRMWAREDIR = ../bin/
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
# LINUX
endif
ifeq ($(UNAME_S),Darwin)
# OSX
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
# ->AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
# ->IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
# ->ARM
endif
WGET = wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused
endif
#############################################################
ESPTOOL ?= ../tools/esptool.py
GITHUB_SDK = https://github.com/espressif/ESP8266_NONOS_SDK
GITHUB_ESPTOOL = https://github.com/espressif/esptool
ESPTOOL ?= $(TOP_DIR)/tools/toolchains/esptool.py
SUBDIRS ?= $(patsubst %/,%,$(dir $(filter-out tools/Makefile,$(wildcard */Makefile))))
ODIR := .output
ifdef TARGET
CSRCS ?= $(wildcard *.c)
CXXSRCS ?= $(wildcard *.cpp)
ASRCs ?= $(wildcard *.s)
ASRCS ?= $(wildcard *.S)
SUBDIRS ?= $(patsubst %/,%,$(dir $(filter-out tools/Makefile,$(wildcard */Makefile))))
ODIR := .output
OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj
OBJS := $(CSRCS:%.c=$(OBJODIR)/%.o) \
......@@ -160,19 +199,19 @@ BINODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/bin
OBINS := $(GEN_BINS:%=$(BINODIR)/%)
ifndef PDIR
ifneq ($(wildcard $(TOP_DIR)/local/fs/*),)
SPECIAL_MKTARGETS += spiffs-image
else
SPECIAL_MKTARGETS += spiffs-image-remove
endif
ifneq ($(wildcard $(TOP_DIR)/local/fs/*),)
SPECIAL_MKTARGETS += spiffs-image
else
SPECIAL_MKTARGETS += spiffs-image-remove
endif
endif
endif # TARGET
#
# Note:
# https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
# If you add global optimize options like "-O2" here
# they will override "-Os" defined above.
# "-Os" should be used to reduce code size
# If you add global optimize options then they will override "-Os" defined above.
# Note that "-Os" should NOT be used to reduce code size because of the runtime
# impact of the extra non-aligned exception burdon.
#
CCFLAGS += \
-g \
......@@ -183,7 +222,7 @@ CCFLAGS += \
-fno-inline-functions \
-nostdlib \
-mlongcalls \
-mtext-section-literals
-mtext-section-literals \
# -Wall
CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
......@@ -194,6 +233,8 @@ DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
# Functions
#
ifdef TARGET
define ShortcutRule
$(1): .subdirs $(2)/$(1)
endef
......@@ -226,70 +267,82 @@ $(BINODIR)/%.bin: $(IMAGEODIR)/%.out
$(summary) ESPTOOL $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$< $(FIRMWAREDIR)
$(ESPTOOL) elf2image --flash_mode dio --flash_freq 40m $< -o $(FIRMWAREDIR)
endif # TARGET
#############################################################
# Rules base
# Should be done in top-level makefile only
#
all: toolchain sdk_pruned pre_build .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
ifndef TARGET
all: toolchain sdk_pruned pre_build buildinfo .subdirs
else
all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
endif
.PHONY: sdk_extracted
.PHONY: sdk_patched
.PHONY: sdk_pruned
.PHONY: toolchain
sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER)
sdk_patched: sdk_extracted $(TOP_DIR)/sdk/.patched-$(SDK_VER)
sdk_pruned: $(SDK_DIR_DEPENDS) $(TOP_DIR)/sdk/.pruned-$(SDK_VER)
sdk_extracted: $(TOP_DIR)/sdk/.extracted-$(SDK_VER)
sdk_pruned: sdk_extracted toolchain $(TOP_DIR)/sdk/.pruned-$(SDK_VER)
ifeq ($(OS),Windows_NT)
toolchain:
else
toolchain: $(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc
ifdef GITHUB_TOOLCHAIN
TOOLCHAIN_ROOT := $(TOP_DIR)/tools/toolchains/esp8266-linux-x86_64-$(TOOLCHAIN_VERSION)
toolchain: $(TOOLCHAIN_ROOT)/bin $(ESPTOOL)
$(TOP_DIR)/tools/toolchains/esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION)/bin/xtensa-lx106-elf-gcc: $(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz
$(TOOLCHAIN_ROOT)/bin: $(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz
mkdir -p $(TOP_DIR)/tools/toolchains/
$(summary) EXTRACT $(patsubst $(TOP_DIR)/%,%,$<)
tar -xJf $< -C $(TOP_DIR)/tools/toolchains/
touch $@
$(TOP_DIR)/cache/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz:
$(TOP_DIR)/cache/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz:
mkdir -p $(TOP_DIR)/cache
$(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@)
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/jmattsson/esp-toolchains/releases/download/$(PLATFORM)-$(TOOLCHAIN_VERSION)/toolchain-esp8266-$(PLATFORM)-$(TOOLCHAIN_VERSION).tar.xz -O $@ || { rm -f "$@"; exit 1; }
$(WGET) $(GITHUB_TOOLCHAIN)/releases/download/$(GCCTOOLCHAIN)/toolchain-esp8266-$(GCCTOOLCHAIN).tar.xz -O $@ \
|| { rm -f "$@"; exit 1; }
else
toolchain: $(ESPTOOL)
endif
$(TOP_DIR)/sdk/.extracted-$(SDK_BASE_VER): $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip
mkdir -p "$(dir $@)"
$(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<)
(cd "$(dir $@)" && rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-$(SDK_BASE_VER) && unzip $(TOP_DIR)/cache/v$(SDK_FILE_VER).zip ESP8266_NONOS_SDK-$(SDK_BASE_VER)/lib/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/ld/eagle.rom.addr.v6.ld ESP8266_NONOS_SDK-$(SDK_BASE_VER)/include/* ESP8266_NONOS_SDK-$(SDK_BASE_VER)/bin/esp_init_data_default_v05.bin)
mv $(dir $@)/ESP8266_NONOS_SDK-$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER)
$(ESPTOOL): $(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz
mkdir -p $(TOP_DIR)/tools/toolchains/
tar -C $(TOP_DIR)/tools/toolchains/ -xzf $< --strip-components=1 esptool-$(ESPTOOL_VER)/esptool.py
chmod +x $@
touch $@
$(TOP_DIR)/sdk/.patched-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_PATCH_VER).patch
mv $(dir $@)/esp_iot_sdk_v$(SDK_BASE_VER) $(dir $@)/esp_iot_sdk_v$(SDK_VER)
$(summary) APPLY $(patsubst $(TOP_DIR)/%,%,$<)
git apply --verbose -p1 --exclude='*VERSION' --exclude='*bin/at*' --directory=$(SDK_REL_DIR) $<
$(TOP_DIR)/cache/esptool/v$(ESPTOOL_VER).tar.gz:
mkdir -p $(TOP_DIR)/cache/esptool/
$(WGET) $(GITHUB_ESPTOOL)/archive/v$(ESPTOOL_VER).tar.gz -O $@ || { rm -f "$@"; exit 1; }
$(TOP_DIR)/sdk/.extracted-$(SDK_VER): $(TOP_DIR)/cache/$(SDK_FILE_VER).zip
mkdir -p "$(dir $@)"
$(summary) UNZIP $(patsubst $(TOP_DIR)/%,%,$<)
(cd "$(dir $@)" && \
rm -fr esp_iot_sdk_v$(SDK_VER) ESP8266_NONOS_SDK-* && \
unzip $(TOP_DIR)/cache/$(SDK_FILE_VER).zip \
'*/lib/*' \
'*/ld/*.v6.ld' \
'*/include/*' \
'*/bin/esp_init_data_default_v05.bin' \
)
mv $(dir $@)/$(SDK_ZIP_ROOT) $(dir $@)/esp_iot_sdk_v$(SDK_VER)
touch $@
$(TOP_DIR)/sdk/.pruned-$(SDK_VER):
rm -f $(SDK_DIR)/lib/liblwip.a $(SDK_DIR)/lib/libssl.a $(SDK_DIR)/lib/libmbedtls.a
$(summary) PRUNE libmain.a libc.a
echo $(PATH)
$(AR) d $(SDK_DIR)/lib/libmain.a time.o
$(AR) d $(SDK_DIR)/lib/libc.a lib_a-time.o
touch $@
$(TOP_DIR)/cache/v$(SDK_FILE_VER).zip:
$(TOP_DIR)/cache/$(SDK_FILE_VER).zip:
mkdir -p "$(dir $@)"
$(summary) WGET $(patsubst $(TOP_DIR)/%,%,$@)
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused https://github.com/espressif/ESP8266_NONOS_SDK/archive/v$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; }
(echo "$(SDK_FILE_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; }
$(TOP_DIR)/cache/$(SDK_PATCH_VER).patch:
mkdir -p "$(dir $@)"
$(summary) WGET $(SDK_PATCH_VER).patch
wget --tries=10 --timeout=15 --waitretry=30 --read-timeout=20 --retry-connrefused "https://github.com/espressif/ESP8266_NONOS_SDK/compare/v$(SDK_BASE_VER)...$(SDK_PATCH_VER).patch" -O $@ || { rm -f "$@"; exit 1; }
(echo "$(SDK_PATCH_SHA1) $@" | sha1sum -c -) || { rm -f "$@"; exit 1; }
$(WGET) $(GITHUB_SDK)/archive/$(SDK_FILE_VER).zip -O $@ || { rm -f "$@"; exit 1; }
if test "$(SDK_FILE_SHA1)" != "NA"; then echo "$(SDK_FILE_SHA1) $@" | sha1sum -c - || { rm -f "$@"; exit 1; }; fi
clean:
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clean;)
......@@ -318,7 +371,7 @@ flash1m-dout:
flashinternal:
ifndef PDIR
$(MAKE) -C ./app flashinternal
$(MAKE) -C $(APP_DIR) flashinternal
else
$(ESPTOOL) --port $(ESPPORT) --baud $(BAUDRATE) write_flash $(FLASHOPTIONS) 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin
endif
......@@ -326,15 +379,12 @@ endif
.subdirs:
@set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);)
#.subdirs:
# $(foreach d, $(SUBDIRS), $(MAKE) -C $(d))
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),clobber)
ifdef DEPS
sinclude $(DEPS)
endif
endif
ifneq ($(MAKECMDGOALS),clobber)
ifdef DEPS
sinclude $(DEPS)
endif
endif
endif
.PHONY: spiffs-image-remove
......@@ -346,22 +396,28 @@ spiffs-image-remove:
spiffs-image: bin/0x10000.bin
$(MAKE) -C tools
############ Note: this target needs moving into app/modules make ############
.PHONY: pre_build
ifneq ($(wildcard $(TOP_DIR)/server-ca.crt),)
pre_build: $(TOP_DIR)/app/modules/server-ca.crt.h
pre_build: $(APP_DIR)/modules/server-ca.crt.h
$(TOP_DIR)/app/modules/server-ca.crt.h: $(TOP_DIR)/server-ca.crt
$(APP_DIR)/modules/server-ca.crt.h: $(TOP_DIR)/server-ca.crt
$(summary) MKCERT $(patsubst $(TOP_DIR)/%,%,$<)
python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(TOP_DIR)/app/modules/server-ca.crt.h
python $(TOP_DIR)/tools/make_server_cert.py $(TOP_DIR)/server-ca.crt > $(APP_DIR)/modules/server-ca.crt.h
DEFINES += -DHAVE_SSL_SERVER_CRT=\"server-ca.crt.h\"
else
pre_build:
@-rm -f $(TOP_DIR)/app/modules/server-ca.crt.h
@-rm -f $(APP_DIR)/modules/server-ca.crt.h
endif
.PHONY: buildinfo
buildinfo:
tools/update_buildinfo.sh
ifdef TARGET
$(OBJODIR)/%.o: %.c
@mkdir -p $(dir $@);
$(summary) CC $(patsubst $(TOP_DIR)/%,%,$(CURDIR))/$<
......@@ -421,6 +477,7 @@ $(foreach lib,$(GEN_LIBS),$(eval $(call MakeLibrary,$(basename $(lib)))))
$(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image)))))
endif # TARGET
#############################################################
# Recursion Magic - Don't touch this!!
#
......@@ -433,6 +490,5 @@ $(foreach image,$(GEN_IMAGES),$(eval $(call MakeImage,$(basename $(image)))))
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include -I $(PDIR)include/$(TARGET)
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
# **NodeMCU 2.2.1** #
# NodeMCU 3.0.0
[![Join the chat at https://gitter.im/nodemcu/nodemcu-firmware](https://img.shields.io/gitter/room/badges/shields.svg)](https://gitter.im/nodemcu/nodemcu-firmware?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/nodemcu/nodemcu-firmware.svg)](https://travis-ci.org/nodemcu/nodemcu-firmware)
......@@ -14,7 +14,7 @@ The firmware was initially developed as is a companion project to the popular ES
# Summary
- Easy to program wireless node and/or access point
- Based on Lua 5.1.4 (without `debug` & `os` modules)
- Based on Lua 5.1.4 but without `debug`, `io`, `os` and (most of the) `math` modules
- Asynchronous event-driven programming model
- more than **65 built-in modules**
- Firmware available with or without floating point support (integer-only uses less memory)
......
......@@ -15,8 +15,6 @@ TARGET = eagle
#FLAVOR = release
FLAVOR = debug
#EXTRA_CCFLAGS += -u
ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
......@@ -83,7 +81,6 @@ COMPONENTS_eagle.app.v6 = \
uzlib/libuzlib.a \
$(OPT_SEL_COMPONENTS)
# Inspect the modules library and work out which modules need to be linked.
# For each enabled module, a symbol name of the form XYZ_module_selected is
# returned. At link time those names are declared undefined, so those (and
......@@ -97,25 +94,28 @@ LINKFLAGS_eagle.app.v6 = \
-T$(LD_FILE) \
-Wl,@../ld/defsym.rom \
-Wl,--no-check-sections \
-Wl,--wrap=_xtos_set_exception_handler \
-Wl,-static \
$(addprefix -u , $(SELECTED_MODULE_SYMS)) \
-Wl,--start-group \
-lmain \
-lc \
$(DEP_LIBS_eagle.app.v6)\
-Wl,--end-group \
-Wl,--start-group \
-lgcc \
-lhal \
-lphy \
-lpp \
-lnet80211 \
-lsmartconfig \
-lwpa \
-lwpa2 \
-lsmartconfig \
-lcrypto \
-lwps \
$(DEP_LIBS_eagle.app.v6) \
-Wl,--end-group \
-lm
-lc \
-lm \
-Wl,--end-group
# -Wl,--cref
# -Wl,--wrap=_xtos_set_exception_handler
DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
......@@ -131,19 +131,7 @@ DEPENDS_eagle.app.v6 = \
#UNIVERSAL_TARGET_DEFINES = \
# Other potential configuration flags include:
# -DTXRX_TXBUF_DEBUG
# -DTXRX_RXBUF_DEBUG
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -D__ets__ \
-DICACHE_FLASH \
-DLUA_OPTIMIZE_MEMORY=2 \
-DMIN_OPT_LEVEL=2 \
-DLWIP_OPEN_SRC \
-DPBUF_RSV_FOR_WLAN \
-DEBUF_LWIP \
-DUSE_OPTIMIZE_PRINTF \
-DMBEDTLS_USER_CONFIG_FILE=\"user_mbedtls.h\" \
CONFIGURATION_DEFINES += -DLWIP_OPEN_SRC
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
......@@ -153,7 +141,6 @@ DDEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
#############################################################
# Recursion Magic - Don't touch this!!
#
......@@ -165,10 +152,10 @@ DDEFINES += \
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES := -I $(PDIR)libc -I $(PDIR)lua -I $(PDIR)platform \
$(INCLUDES) -I $(PDIR) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
.PHONY: FORCE
......
......@@ -36,10 +36,6 @@ endif
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../libc
INCLUDES += -I ../lua
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
#include "user_config.h"
#include "c_stdio.h"
#include "c_string.h"
#include <stdio.h>
#include <string.h>
#include "coap.h"
#include "uri.h"
......@@ -10,12 +10,12 @@ extern const coap_endpoint_t endpoints[];
#ifdef COAP_DEBUG
void coap_dumpHeader(coap_header_t *hdr)
{
c_printf("Header:\n");
c_printf(" ver 0x%02X\n", hdr->ver);
c_printf(" t 0x%02X\n", hdr->ver);
c_printf(" tkl 0x%02X\n", hdr->tkl);
c_printf(" code 0x%02X\n", hdr->code);
c_printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
printf("Header:\n");
printf(" ver 0x%02X\n", hdr->ver);
printf(" t 0x%02X\n", hdr->ver);
printf(" tkl 0x%02X\n", hdr->tkl);
printf(" code 0x%02X\n", hdr->code);
printf(" id 0x%02X%02X\n", hdr->id[0], hdr->id[1]);
}
void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
......@@ -23,14 +23,14 @@ void coap_dump(const uint8_t *buf, size_t buflen, bool bare)
if (bare)
{
while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
}
else
{
c_printf("Dump: ");
printf("Dump: ");
while(buflen--)
c_printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
c_printf("\n");
printf("%02X%s", *buf++, (buflen > 0) ? " " : "");
printf("\n");
}
}
#endif
......@@ -100,7 +100,7 @@ int coap_buildToken(const coap_buffer_t *tokbuf, const coap_header_t *hdr, uint8
return COAP_ERR_UNSUPPORTED;
if (hdr->tkl > 0)
c_memcpy(p, tokbuf->p, hdr->tkl);
memcpy(p, tokbuf->p, hdr->tkl);
// http://tools.ietf.org/html/rfc7252#section-3.1
// inject options
......@@ -260,12 +260,12 @@ int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_
void coap_dumpOptions(coap_option_t *opts, size_t numopt)
{
size_t i;
c_printf(" Options:\n");
printf(" Options:\n");
for (i=0;i<numopt;i++)
{
c_printf(" 0x%02X [ ", opts[i].num);
printf(" 0x%02X [ ", opts[i].num);
coap_dump(opts[i].buf.p, opts[i].buf.len, true);
c_printf(" ]\n");
printf(" ]\n");
}
}
......@@ -273,9 +273,9 @@ void coap_dumpPacket(coap_packet_t *pkt)
{
coap_dumpHeader(&pkt->hdr);
coap_dumpOptions(pkt->opts, pkt->numopts);
c_printf("Payload: ");
printf("Payload: ");
coap_dump(pkt->payload.p, pkt->payload.len, true);
c_printf("\n");
printf("\n");
}
#endif
......@@ -325,7 +325,7 @@ int coap_buffer_to_string(char *strbuf, size_t strbuflen, const coap_buffer_t *b
{
if (buf->len+1 > strbuflen)
return COAP_ERR_BUFFER_TOO_SMALL;
c_memcpy(strbuf, buf->p, buf->len);
memcpy(strbuf, buf->p, buf->len);
strbuf[buf->len] = 0;
return 0;
}
......@@ -360,7 +360,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
p += rc;
left -= rc;
c_memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len);
memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len);
p += pkt->opts[i].buf.len;
left -= pkt->opts[i].buf.len;
running_delta = pkt->opts[i].num;
......@@ -373,7 +373,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt)
if (*buflen < 4 + 1 + pkt->payload.len + opts_len)
return COAP_ERR_BUFFER_TOO_SMALL;
buf[4 + opts_len] = 0xFF; // payload marker
c_memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len);
memcpy(buf+5 + opts_len, pkt->payload.p, pkt->payload.len);
*buflen = opts_len + 5 + pkt->payload.len;
}
else
......@@ -471,7 +471,7 @@ int coap_make_request(coap_rw_buffer_t *scratch, coap_packet_t *pkt, coap_msgtyp
/* split arg into Uri-* options */
// const char *addr = uri->host.s;
// if(uri->host.length && (c_strlen(addr) != uri->host.length || c_memcmp(addr, uri->host.s, uri->host.length) != 0)){
// if(uri->host.length && (strlen(addr) != uri->host.length || memcmp(addr, uri->host.s, uri->host.length) != 0)){
if(uri->host.length){
/* add Uri-Host */
// addr is destination address
......@@ -525,9 +525,9 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_
goto next;
for (i=0;i<ep->path->count;i++)
{
if (opt[i].buf.len != c_strlen(ep->path->elems[i]))
if (opt[i].buf.len != strlen(ep->path->elems[i]))
goto next;
if (0 != c_memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len))
if (0 != memcmp(ep->path->elems[i], opt[i].buf.p, opt[i].buf.len))
goto next;
}
// pre-path match!
......@@ -551,5 +551,5 @@ void coap_setup(void)
int
check_token(coap_packet_t *pkt) {
return pkt->tok.len == the_token.len && c_memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
return pkt->tok.len == the_token.len && memcmp(pkt->tok.p, the_token.p, the_token.len) == 0;
}
......@@ -5,8 +5,8 @@
extern "C" {
#endif
#include "c_stdint.h"
#include "c_stddef.h"
#include <stdint.h>
#include <stddef.h>
#include "lualib.h"
#include "lauxlib.h"
......
#include "user_config.h"
#include "c_types.h"
#include <stdint.h>
#include "coap.h"
#include "hash.h"
......
#include "c_string.h"
#include <string.h>
#include "coap_io.h"
#include "node.h"
#include "espconn.h"
......@@ -16,10 +16,10 @@ coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu) {
espconn_sent(pesp_conn, (unsigned char *)(pdu->msg.p), pdu->msg.len);
if(pesp_conn->type == ESPCONN_TCP){
c_memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip));
memcpy(&ip, pesp_conn->proto.tcp->remote_ip, sizeof(ip));
port = pesp_conn->proto.tcp->remote_port;
}else{
c_memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip));
memcpy(&ip, pesp_conn->proto.udp->remote_ip, sizeof(ip));
port = pesp_conn->proto.udp->remote_port;
}
coap_transaction_id(ip, port, pdu->pkt, &id);
......
......@@ -5,7 +5,6 @@
extern "C" {
#endif
#include "c_types.h"
#include "lwip/ip_addr.h"
#include "espconn.h"
#include "pdu.h"
......
#include "user_config.h"
#include "c_types.h"
#include "c_stdlib.h"
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include "coap.h"
......@@ -51,7 +52,7 @@ size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned
#endif
}
if(rsppkt.content.p){
c_free(rsppkt.content.p);
free(rsppkt.content.p);
rsppkt.content.p = NULL;
rsppkt.content.len = 0;
}
......
#include "node.h"
#include "coap_timer.h"
#include "os_type.h"
#include "osapi.h"
#include "pm/swtimer.h"
static os_timer_t coap_timer;
......
#include "c_stdio.h"
#include "c_string.h"
#include "c_stdlib.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "coap.h"
#include "lua.h"
......@@ -21,14 +21,14 @@ void endpoint_setup(void)
static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}};
static int handle_get_well_known_core(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
outpkt->content.p = (uint8_t *)c_zalloc(MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond()
outpkt->content.p = (uint8_t *)calloc(1,MAX_PAYLOAD_SIZE); // this should be free-ed when outpkt is built in coap_server_respond()
if(outpkt->content.p == NULL){
NODE_DBG("not enough memory\n");
return COAP_ERR_BUFFER_TOO_SMALL;
}
outpkt->content.len = MAX_PAYLOAD_SIZE;
build_well_known_rsp(outpkt->content.p, outpkt->content.len);
return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, c_strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
return coap_make_response(scratch, outpkt, (const uint8_t *)outpkt->content.p, strlen(outpkt->content.p), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT);
}
static const coap_endpoint_path_t path_variable = {2, {"v1", "v"}};
......@@ -49,17 +49,17 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){
if (opt[count-1].buf.len != c_strlen(h->name))
if (opt[count-1].buf.len != strlen(h->name))
{
h = h->next;
continue;
}
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
{
NODE_DBG("/v1/v/");
NODE_DBG((char *)h->name);
NODE_DBG(" match.\n");
if(c_strlen(h->name))
if(strlen(h->name))
{
n = lua_gettop(L);
lua_getglobal(L, h->name);
......@@ -70,7 +70,7 @@ static int handle_get_variable(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
} else {
const char *res = lua_tostring(L,-1);
lua_settop(L, n);
return coap_make_response(scratch, outpkt, (const uint8_t *)res, c_strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
return coap_make_response(scratch, outpkt, (const uint8_t *)res, strlen(res), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, h->content_type);
}
}
} else {
......@@ -105,18 +105,18 @@ static int handle_post_function(const coap_endpoint_t *ep, coap_rw_buffer_t *scr
{
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){
if (opt[count-1].buf.len != c_strlen(h->name))
if (opt[count-1].buf.len != strlen(h->name))
{
h = h->next;
continue;
}
if (0 == c_memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
if (0 == memcmp(h->name, opt[count-1].buf.p, opt[count-1].buf.len))
{
NODE_DBG("/v1/f/");
NODE_DBG((char *)h->name);
NODE_DBG(" match.\n");
if(c_strlen(h->name))
if(strlen(h->name))
{
n = lua_gettop(L);
lua_getglobal(L, h->name);
......@@ -173,7 +173,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
{
char line[LUA_MAXINPUT];
if (!coap_buffer_to_string(line, LUA_MAXINPUT, &inpkt->payload) &&
lua_put_line(line, c_strlen(line))) {
lua_put_line(line, strlen(line))) {
NODE_DBG("\nResult(if any):\n");
system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0);
}
......@@ -211,7 +211,7 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
int i;
uint16_t len = rsplen;
c_memset(rsp, 0, len);
memset(rsp, 0, len);
len--; // Null-terminated string
......@@ -222,57 +222,57 @@ void build_well_known_rsp(char *rsp, uint16_t rsplen)
continue;
}
if (NULL == ep->user_entry){
if (0 < c_strlen(rsp)) {
c_strncat(rsp, ",", len);
if (0 < strlen(rsp)) {
strncat(rsp, ",", len);
len--;
}
c_strncat(rsp, "<", len);
strncat(rsp, "<", len);
len--;
for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len);
strncat(rsp, "/", len);
len--;
c_strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]);
strncat(rsp, ep->path->elems[i], len);
len -= strlen(ep->path->elems[i]);
}
c_strncat(rsp, ">;", len);
strncat(rsp, ">;", len);
len -= 2;
c_strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr);
strncat(rsp, ep->core_attr, len);
len -= strlen(ep->core_attr);
} else {
coap_luser_entry *h = ep->user_entry->next; // ->next: skip the first entry(head)
while(NULL != h){
if (0 < c_strlen(rsp)) {
c_strncat(rsp, ",", len);
if (0 < strlen(rsp)) {
strncat(rsp, ",", len);
len--;
}
c_strncat(rsp, "<", len);
strncat(rsp, "<", len);
len--;
for (i = 0; i < ep->path->count; i++) {
c_strncat(rsp, "/", len);
strncat(rsp, "/", len);
len--;
c_strncat(rsp, ep->path->elems[i], len);
len -= c_strlen(ep->path->elems[i]);
strncat(rsp, ep->path->elems[i], len);
len -= strlen(ep->path->elems[i]);
}
c_strncat(rsp, "/", len);
strncat(rsp, "/", len);
len--;
c_strncat(rsp, h->name, len);
len -= c_strlen(h->name);
strncat(rsp, h->name, len);
len -= strlen(h->name);
c_strncat(rsp, ">;", len);
strncat(rsp, ">;", len);
len -= 2;
c_strncat(rsp, ep->core_attr, len);
len -= c_strlen(ep->core_attr);
strncat(rsp, ep->core_attr, len);
len -= strlen(ep->core_attr);
h = h->next;
}
......
#include "hash.h"
#include "c_string.h"
#include <string.h>
/* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY
* accordingly (see int coap_hash_path());
*/
......@@ -20,7 +20,7 @@ void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) {
void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id) {
coap_key_t h;
c_memset(h, 0, sizeof(coap_key_t));
memset(h, 0, sizeof(coap_key_t));
/* Compare the transport address. */
coap_hash((const unsigned char *)&(port), sizeof(port), h);
......
#include "c_string.h"
#include "c_stdlib.h"
#include <string.h>
#include <stdlib.h>
#include "node.h"
static inline coap_queue_t *
coap_malloc_node(void) {
return (coap_queue_t *)c_zalloc(sizeof(coap_queue_t));
return (coap_queue_t *)calloc(1,sizeof(coap_queue_t));
}
void coap_free_node(coap_queue_t *node) {
c_free(node);
free(node);
}
int coap_insert_node(coap_queue_t **queue, coap_queue_t *node) {
......@@ -73,7 +73,7 @@ coap_queue_t * coap_new_node(void) {
return NULL;
}
c_memset(node, 0, sizeof(*node));
memset(node, 0, sizeof(*node));
return node;
}
......
#include "c_stdlib.h"
#include <stdlib.h>
#include "pdu.h"
coap_pdu_t * coap_new_pdu(void) {
coap_pdu_t *pdu = NULL;
pdu = (coap_pdu_t *)c_zalloc(sizeof(coap_pdu_t));
pdu = (coap_pdu_t *)calloc(1,sizeof(coap_pdu_t));
if(!pdu){
NODE_DBG("coap_new_pdu malloc error.\n");
return NULL;
}
pdu->scratch.p = (uint8_t *)c_zalloc(MAX_REQ_SCRATCH_SIZE);
pdu->scratch.p = (uint8_t *)calloc(1,MAX_REQ_SCRATCH_SIZE);
if(!pdu->scratch.p){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu);
free(pdu);
return NULL;
}
pdu->scratch.len = MAX_REQ_SCRATCH_SIZE;
pdu->pkt = (coap_packet_t *)c_zalloc(sizeof(coap_packet_t));
pdu->pkt = (coap_packet_t *)calloc(1,sizeof(coap_packet_t));
if(!pdu->pkt){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->scratch.p);
c_free(pdu);
free(pdu->scratch.p);
free(pdu);
return NULL;
}
pdu->pkt->content.p = NULL;
pdu->pkt->content.len = 0;
pdu->msg.p = (uint8_t *)c_zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0'
pdu->msg.p = (uint8_t *)calloc(1,MAX_REQUEST_SIZE+1); // +1 for string '\0'
if(!pdu->msg.p){
NODE_DBG("coap_new_pdu malloc error.\n");
c_free(pdu->pkt);
c_free(pdu->scratch.p);
c_free(pdu);
free(pdu->pkt);
free(pdu->scratch.p);
free(pdu);
return NULL;
}
pdu->msg.len = MAX_REQUEST_SIZE;
......@@ -44,22 +44,22 @@ void coap_delete_pdu(coap_pdu_t *pdu){
return;
if(pdu->scratch.p){
c_free(pdu->scratch.p);
free(pdu->scratch.p);
pdu->scratch.p = NULL;
pdu->scratch.len = 0;
}
if(pdu->pkt){
c_free(pdu->pkt);
free(pdu->pkt);
pdu->pkt = NULL;
}
if(pdu->msg.p){
c_free(pdu->msg.p);
free(pdu->msg.p);
pdu->msg.p = NULL;
pdu->msg.len = 0;
}
c_free(pdu);
free(pdu);
pdu = NULL;
}
......@@ -6,23 +6,23 @@
* README for terms of use.
*/
#include "c_stdlib.h"
#include "c_types.h"
#include <stdlib.h>
#include <stddef.h>
#include "str.h"
str * coap_new_string(size_t size) {
str *s = (str *)c_malloc(sizeof(str) + size + 1);
str *s = (str *)malloc(sizeof(str) + size + 1);
if ( !s ) {
return NULL;
}
c_memset(s, 0, sizeof(str));
memset(s, 0, sizeof(str));
s->s = ((unsigned char *)s) + sizeof(str);
return s;
}
void coap_delete_string(str *s) {
c_free(s);
free(s);
}
......@@ -9,7 +9,7 @@
#ifndef _COAP_STR_H_
#define _COAP_STR_H_
#include "c_string.h"
#include <string.h>
typedef struct {
size_t length; /* length of string */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment