GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags) include ../version.mk include $(FW_PATH)/definitions.mk LOCAL_SRCS=$(wildcard src/*.c) OBJS=$(addprefix obj/,$(notdir $(LOCAL_SRCS:.c=.o))) CFLAGS= \ -fplugin=$(CCPLUGIN) \ -fplugin-arg-nexmon-objfile=$@ \ -fplugin-arg-nexmon-prefile=gen/nexmon.pre \ -fplugin-arg-nexmon-chipver=$(NEXMON_CHIP_NUM) \ -fplugin-arg-nexmon-fwver=$(NEXMON_FW_VERSION_NUM) \ -fno-strict-aliasing \ -DNEXMON_CHIP=$(NEXMON_CHIP) \ -DNEXMON_FW_VERSION=$(NEXMON_FW_VERSION) \ -DPATCHSTART=$(PATCHSTART) \ -DUCODESIZE=$(UCODESIZE) \ -DGIT_VERSION=\"$(GIT_VERSION)\" \ -DBUILD_NUMBER=\"$$(cat BUILD_NUMBER)\" \ -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding -mthumb -march=$(NEXMON_ARCH) \ -ffunction-sections -fdata-sections \ -I$(NEXMON_ROOT)/patches/include \ -Iinclude \ -I$(FW_PATH) all: fw_bcmdhd.bin init: FORCE $(Q)if ! test -f BUILD_NUMBER; then echo 0 > BUILD_NUMBER; fi $(Q)echo $$(($$(cat BUILD_NUMBER) + 1)) > BUILD_NUMBER $(Q)touch src/version.c $(Q)make -s -f $(NEXMON_ROOT)/patches/common/header.mk $(Q)mkdir -p obj gen log obj/%.o: src/%.c @printf "\033[0;31m COMPILING\033[0m %s => %s (details: log/compiler.log)\n" $< $@ $(Q)cat gen/nexmon.pre 2>>log/error.log | gawk '{ if ($$3 != "$@") print; }' > tmp && mv tmp gen/nexmon.pre $(Q)$(CC)gcc $(CFLAGS) -c $< -o $@ >>log/compiler.log gen/nexmon2.pre: $(OBJS) @printf "\033[0;31m PREPARING\033[0m %s => %s\n" "gen/nexmon.pre" $@ $(Q)cat gen/nexmon.pre | awk '{ if ($$3 != "obj/flashpatches.o" && $$3 != "obj/wrapper.o") { print $$0; } }' > tmp $(Q)cat gen/nexmon.pre | awk '{ if ($$3 == "obj/flashpatches.o" || $$3 == "obj/wrapper.o") { print $$0; } }' >> tmp $(Q)cat tmp | awk '{ if ($$1 ~ /^0x/) { if ($$3 != "obj/flashpatches.o" && $$3 != "obj/wrapper.o") { if (!x[$$1]++) { print $$0; } } else { if (!x[$$1]) { print $$0; } } } else { print $$0; } }' > gen/nexmon2.pre gen/nexmon.ld: gen/nexmon2.pre $(OBJS) @printf "\033[0;31m GENERATING LINKER FILE\033[0m gen/nexmon.pre => %s\n" $@ $(Q)sort gen/nexmon2.pre | gawk -f $(NEXMON_ROOT)/buildtools/scripts/nexmon.ld.awk > $@ gen/nexmon.mk: gen/nexmon2.pre $(OBJS) $(FW_PATH)/definitions.mk @printf "\033[0;31m GENERATING MAKE FILE\033[0m gen/nexmon.pre => %s\n" $@ $(Q)printf "fw_bcmdhd.bin: gen/patch.elf FORCE\n" > $@ $(Q)sort gen/nexmon2.pre | \ gawk -v src_file=gen/patch.elf -f $(NEXMON_ROOT)/buildtools/scripts/nexmon.mk.1.awk | \ gawk -v ramstart=$(RAMSTART) -f $(NEXMON_ROOT)/buildtools/scripts/nexmon.mk.2.awk >> $@ $(Q)printf "\nFORCE:\n" >> $@ $(Q)gawk '!a[$$0]++' $@ > tmp && mv tmp $@ gen/memory.ld: $(FW_PATH)/definitions.mk @printf "\033[0;31m GENERATING LINKER FILE\033[0m %s\n" $@ $(Q)printf "rom : ORIGIN = 0x%08x, LENGTH = 0x%08x\n" $(ROMSTART) $(ROMSIZE) > $@ $(Q)printf "ram : ORIGIN = 0x%08x, LENGTH = 0x%08x\n" $(RAMSTART) $(RAMSIZE) >> $@ $(Q)printf "patch : ORIGIN = 0x%08x, LENGTH = 0x%08x\n" $(PATCHSTART) $(PATCHSIZE) >> $@ gen/patch.elf: patch.ld gen/nexmon.ld gen/memory.ld $(OBJS) @printf "\033[0;31m LINKING OBJECTS\033[0m => %s (details: log/linker.log, log/linker.err)\n" $@ $(Q)$(CC)ld -T $< -o $@ --gc-sections --print-gc-sections -M >>log/linker.log 2>>log/linker.err fw_bcmdhd.bin: init gen/patch.elf $(FW_PATH)/$(RAM_FILE) gen/nexmon.mk $(Q)cp $(FW_PATH)/$(RAM_FILE) $@ @printf "\033[0;31m APPLYING PATCHES\033[0m gen/nexmon.mk => %s (details: log/patches.log)\n" $@ $(Q)make -f gen/nexmon.mk >>log/patches.log 2>>log/flashpatches.log check-nexmon-setup-env: ifndef NEXMON_SETUP_ENV $(error run 'source setup_env.sh' first in the repository\'s root directory) endif dump-rom: fw_bcmdhd.bin @printf "\033[0;31m COPYING TO PHONE\033[0m %s => /sdcard/%s\n" $< $< $(Q)adb push $< /sdcard/ >> log/adb.log 2>> log/adb.log @printf "\033[0;31m LOADING FIRMWARE\033[0m /sdcard/fw_bcmdhd.bin\n" $(Q)adb shell 'su -c "dhdutil download /sdcard/fw_bcmdhd.bin"' @printf "\033[0;31m DUMPING ROM\033[0m ROM => /sdcard/rom.bin\n" $(Q)adb shell 'su -c "dhdutil membytes -r 0x181000 $(ROMSIZE) > /sdcard/rom.bin"' @printf "\033[0;31m PULLING\033[0m /sdcard/rom.bin => rom.bin\n" $(Q)adb pull /sdcard/rom.bin rom.bin @printf "\033[0;31m RELOADING PREVIOUS FIRMWARE\033[0m\n" $(Q)adb shell 'su -c "ifconfig wlan0 down && ifconfig wlan0 up"' @printf "\033[0;31m COPYING ROM\033[0m rom.bin => $(NEXMON_ROOT)/firmwares/bcm4356/rom.bin\n" $(Q)cp rom.bin $(NEXMON_ROOT)/firmwares/bcm4356/rom.bin backup-firmware: FORCE adb shell 'su -c "cp /vendor/firmware/fw_bcmdhd.bin /sdcard/fw_bcmdhd.orig.bin"' adb pull /sdcard/fw_bcmdhd.orig.bin install-backup: fw_bcmdhd.orig.bin adb shell 'su -c "mount -o rw,remount /system"' && \ adb push $< /sdcard/ && \ adb shell 'su -c "cp /sdcard/fw_bcmdhd.bin /vendor/firmware/fw_bcmdhd.bin"' adb shell 'su -c "ifconfig wlan0 down && ifconfig wlan0 up"' clean-firmware: FORCE @printf "\033[0;31m CLEANING\033[0m\n" $(Q)rm -fr fw_bcmdhd.bin obj gen log clean: clean-firmware $(Q)rm -f BUILD_NUMBER rom.bin FORCE: