forked from kendryte/k510_buildroot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·177 lines (140 loc) · 6.95 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
BR2_VERSION = 2020.02.11
RED=\e[1;31m
NC=\e[0m
SHELL=/bin/bash
BRW_ROOT = $(PWD)
BRW_SITE = https://buildroot.org/downloads/buildroot-$(BR2_VERSION).tar.gz
BRW_FILE = $(BR2_DL_DIR)/buildroot-$(BR2_VERSION).tar.gz
BRW_DIR = $(BRW_ROOT)/buildroot-$(BR2_VERSION)
BRW_PATCH_DIR = $(BRW_ROOT)/patches
TOOLCHAIN_DIR = $(BRW_ROOT)/toolchain
TOOLCHAIN_NAME = nds64le-linux-glibc-v5d
TOOLCHAIN_DIR_SITE =https://github.com/andestech/Andes-Development-Kit/releases/download/ast-v3_2_1-release-linux
TOOLCHAIN_NAME_MCU = nds64le-elf-mculib-v5d
TOOLCHAIN_MCU_DIR_SITE =https://github.com/andestech/Andes-Development-Kit/releases/download/ast-v3_2_3-release-linux
#DEMO_DIR = $(BRW_ROOT)/demo
#ROOTFS_OVERLAY_PATH = $(BRW_ROOT)/board/canaan/k510/rootfs_overlay
CONF ?= "k510_crb_lp3_v1_2_defconfig"
O ?= $(CONF)
BR2_DL_DIR ?= $(BRW_ROOT)/dl
define DOWNLOAD
set -e;\
if [ ! -d $(BR2_DL_DIR) ]; then \
if [ -f pkg-download/dl.tar.gz ]; then \
tar -zxf pkg-download/dl.tar.gz || { echo -e "\n\nfile pkg-download/dl.tar.gz is error,please delete .\n";exit 1; } ; \
fi; \
mkdir -p $(BR2_DL_DIR); \
fi; \
if [ ! -f $(BRW_FILE) ]; then \
wget -c $(BRW_SITE) -O $(BRW_FILE); \
fi; \
endef
define COPYFILES
set -e; \
if [ ! -d $(BRW_DIR) ]; then \
tar --no-same-owner -zxf $(BRW_FILE) -C $(BRW_ROOT); \
if [ "'ls $(BRW_PATCH_DIR)/*.patch'" != "" ]; then \
$(BRW_DIR)/support/scripts/apply-patches.sh $(BRW_DIR) $(BRW_PATCH_DIR); \
fi; \
fi; \
if [ ! -d $(TOOLCHAIN_DIR)/$(TOOLCHAIN_NAME) ]; then \
tar --no-same-owner -xf $(TOOLCHAIN_DIR)/$(TOOLCHAIN_NAME).txz -C $(TOOLCHAIN_DIR); \
fi; \
[ -d $(TOOLCHAIN_DIR)/$(TOOLCHAIN_NAME_MCU) ] || tar --no-same-owner -xf $(TOOLCHAIN_DIR)/$(TOOLCHAIN_NAME_MCU).txz -C $(TOOLCHAIN_DIR);
endef
define CLEAN
set -e; \
cd $(BRW_ROOT); \
rm -rf $(CONF); \
rm -rf $(BRW_DIR); \
endef
.PHONY: all
all .DEFAULT: down_toolchain
@$(call DOWNLOAD)
@$(call COPYFILES)
make -C $(BRW_DIR) $(CONF) O=$(BRW_ROOT)/$(O) BR2_EXTERNAL=$(BRW_ROOT)
make -C $(BRW_ROOT)/$(O)
.PHONY: source
source:
@$(call DOWNLOAD)
@$(call COPYFILES)
make -C $(BRW_DIR) $(CONF) O=$(BRW_ROOT)/$(O) BR2_EXTERNAL=$(BRW_ROOT)
make -C $(BRW_ROOT)/$(O) source
.PHONY: menuconfig
menuconfig:
make -C $(BRW_ROOT)/$(O) menuconfig
.PHONY: build
build:
make -C $(BRW_ROOT)/$(O)
.PHONY: savedefconfig
savedefconfig:
make -C $(BRW_ROOT)/$(O) savedefconfig
.PHONY: clean
clean:
@$(call CLEAN)
.PHONY:down_toolchain dl
dl:
rm -rf pkg-download/dl.tar.gz;
wget -c https://github.com/kendryte/k510_buildroot/releases/download/v1.6/dl.tar.gz -O pkg-download/dl.tar.gz;
tar -zxf pkg-download/dl.tar.gz;
mkdir -p dl/ai/; wget -c https://github.com/kendryte/k510_buildroot/releases/download/v1.7/ai_kmodel_data.tar.xz -O dl/ai/ai_kmodel_data.tar.xz;
(set -xe; NNCASE_VER=v1.7.1 ;\
NNCASE_SITE=https://github.com/kendryte/nncase/releases/download;\
NNCASE_PIP_VD=1.7.1.20220701 ; \
NNCASE_PIP_K510_VD=1.7.1.20220701 ;\
mkdir -p dl/nncase_linux_runtime; cd dl/nncase_linux_runtime; \
wget -c $${NNCASE_SITE}/$${NNCASE_VER}/nncaseruntime-k510-v1.7.1.tgz ; \
wget -c $${NNCASE_SITE}/$${NNCASE_VER}/nncase-$${NNCASE_PIP_VD}-cp310-cp310-manylinux_2_24_x86_64.whl; \
wget -c $${NNCASE_SITE}/$${NNCASE_VER}/nncase-$${NNCASE_PIP_VD}-cp36-cp36m-manylinux_2_24_x86_64.whl;\
wget -c $${NNCASE_SITE}/$${NNCASE_VER}/nncase-$${NNCASE_PIP_VD}-cp37-cp37m-manylinux_2_24_x86_64.whl;\
wget -c $${NNCASE_SITE}/$${NNCASE_VER}/nncase-$${NNCASE_PIP_VD}-cp38-cp38-manylinux_2_24_x86_64.whl;\
wget -c $${NNCASE_SITE}/$${NNCASE_VER}/nncase-$${NNCASE_PIP_VD}-cp39-cp39-manylinux_2_24_x86_64.whl; \
wget -c $${NNCASE_SITE}/$${NNCASE_VER}/nncase_k510-$${NNCASE_PIP_K510_VD}-py2.py3-none-manylinux_2_24_x86_64.whl; \
)
down_toolchain:
if [ ! -f toolchain/$(TOOLCHAIN_NAME).txz ] || [ "c87c87089fe2f0445a94054e8ae7b947" != "$(shell md5sum toolchain/$(TOOLCHAIN_NAME).txz | cut -d' ' -f1 )" ]; then \
rm -rf toolchain/$(TOOLCHAIN_NAME)* ;\
wget -c $(TOOLCHAIN_DIR_SITE)/$(TOOLCHAIN_NAME).txz -O toolchain/$(TOOLCHAIN_NAME).txz;\
tar --no-same-owner -xf $(TOOLCHAIN_DIR)/$(TOOLCHAIN_NAME).txz -C $(TOOLCHAIN_DIR);\
fi;
if [ ! -f toolchain/$(TOOLCHAIN_NAME_MCU).txz ] || [ "d2dcf2729c2e6b654c4be197c2c75987" != "$(shell md5sum toolchain/$(TOOLCHAIN_NAME_MCU).txz | cut -d' ' -f1 )" ]; then\
rm -rf toolchain/$(TOOLCHAIN_NAME_MCU)* ;\
wget -c $(TOOLCHAIN_MCU_DIR_SITE)/$(TOOLCHAIN_NAME_MCU).txz -O toolchain/$(TOOLCHAIN_NAME_MCU).txz;\
tar --no-same-owner -xf $(TOOLCHAIN_DIR)/$(TOOLCHAIN_NAME_MCU).txz -C $(TOOLCHAIN_DIR);\
fi;
#mkfs.ext4 -d $${dir} $(BR2_DL_DIR)/debian_rootfs.ext4 3G;
#update_debian: SHELL=/bin/bash
debian:
@[ -f ${CONF}/images/sysimage-sdcard.img ] || { echo "please first use 'make CONF=${CONF}' command build sdk!"; exit 1; }
echo "please change to root user or sudo -s make update_debian"
(set -xe; dir=debian; debian_tar=$(shell pwd)/board/canaan/k510/debian.tar.gz; rm -rf $${dir} $${debian_tar}; \
wget http://ftp.cn.debian.org/debian/pool/main/d/debian-ports-archive-keyring/debian-ports-archive-keyring_2022.02.15_all.deb;\
dpkg -i debian-ports-archive-keyring_2022.02.15_all.deb;rm -rf debian-ports-archive-keyring_2022.02.15_all.deb;\
debootstrap --arch=riscv64 --keyring /usr/share/keyrings/debian-ports-archive-keyring.gpg \
--include=debian-ports-archive-keyring unstable $${dir} http://deb.debian.org/debian-ports; \
chroot $${dir} apt-get update; chroot $${dir} apt-get install -y ntpdate libgomp1 libatomic1; \
echo "root:root" | chroot $${dir} chpasswd;\
chroot "$$dir" adduser --gecos "Debian user,,," --disabled-password debian ;\
echo "debian:debian" | chroot $$dir chpasswd;\
echo "debian" > $${dir}/etc/hostname;\
echo -e '#!/bin/bash -e \nntpdate ntp.aliyun.com\n' >$${dir}/etc/rc.local; chmod +x $${dir}/etc/rc.local; \
echo -e "auto lo\niface lo inet loopback\n\n\nauto eth0\niface eth0 inet dhcp \n" > $${dir}/etc/network/interfaces;\
chroot $${dir} rm -rf /etc/localtime ; chroot $${dir} ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ;\
rsync -a --ignore-times --chmod=u=rwX,go=rX board/canaan/k510/debian_rootfs_overlay/ $${dir}; \
chroot $${dir} systemctl enable rootfs_fsck;\
tar -cjf $${debian_tar} $${dir} ; chmod a+rw $${debian_tar};rm -rf $${dir};\
echo "file is $${debian_tar} ";\
export CONF=${CONF} ; ./board/canaan/k510/debian.sh ;\
echo "debian image is ${CONF}/images/sysimage-sdcard-debian.img";\
)
update_debian_from_last_version:
(set -xe; dir=debian; debian_tar=$(shell pwd)/board/canaan/k510/debian.tar.gz; rm -rf $${dir}; tar -xf $${debian_tar}; \
rsync -a --ignore-times --chmod=u=rwX,go=rX board/canaan/k510/debian_rootfs_overlay/ $${dir}; \
chroot $${dir} systemctl enable rootfs_fsck;\
rm -rf $${debian_tar}; tar -cjf $${debian_tar} $${dir} ; chmod a+rw $${debian_tar};\
)
help:
@echo "debian---generate debian image,note:need root privileged "
@echo "source---down all code "
@echo "build---only build"
@echo "all---default,example:make CONF=k510_crb_lp3_v1_2_defconfig"