Duo运行golang网络程序

1、下载duo-buildroot-sdk
2、修改sdk目录build/boards/cv180x/cv1800b_milkv_duo_sd/linux/cvitek_cv1800b_milkv_duo_sd_defconfig文件,最后一行CONFIG_EPOLL=y
3、修改内存配置,编辑文件build/boards/cv180x/cv1800b_milkv_duo_sd/memmap.py,第43行改为ION_SIZE = 0 * SIZE_1M
4、 运行build_milkv.sh构建并烧写镜像
5、Golang程序编写
package main

import (
“log”
“net/http”
)

func main() {

err := http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	_, err := w.Write([]byte("Hello World"))
	if err != nil {
		log.Fatal(err)
	}
}))
if err != nil {
	log.Fatal(err)
}

}

6、交叉编译: CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -ldflags=“-s -w” -o hello_world
7、程序scp到/root目录并运行 ./hello_world
8、在别处访问: curl http://ip:8080/
9、经过free -m查询内存占用1M左右

2 Likes

Worked for me! Thanks for sharing!
I wonder why it didn’t work until I changed ION_SIZE to zero. The program itself takes only about 1 MB so it should fit the memory even with the default image – there were about 7 MB free.

1 Like