From 954537d2b3a8e9564936428f1e968615b7e38aac Mon Sep 17 00:00:00 2001 From: shanker JJ Date: Mon, 21 Nov 2022 22:35:15 +0900 Subject: [PATCH] Support for MIPs arch --- .github/workflows/buildandrelease.yml | 65 ++++++++++++++++++++++++--- netclient/bin-maker.sh | 13 +++--- scripts/netclient-install.sh | 11 ++++- 3 files changed, 75 insertions(+), 14 deletions(-) diff --git a/.github/workflows/buildandrelease.yml b/.github/workflows/buildandrelease.yml index 3251b5a5..7d323d33 100644 --- a/.github/workflows/buildandrelease.yml +++ b/.github/workflows/buildandrelease.yml @@ -294,18 +294,49 @@ jobs: - name: Build run: | cd netclient - env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w -X 'main.version=$NETMAKER_VERSION'" -o build/netclient-mipsle/netclient main.go && upx build/netclient-mipsle/netclient + env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w -X 'main.version=$NETMAKER_VERSION'" -o build/netclient-mipsle/netclient-mipsle main.go && upx -o build/netclient-mipsle/netclient-mipsle-upx build/netclient-mipsle/netclient-mipsle + env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -X 'main.version=$NETMAKER_VERSION'" -o build/netclient-mipsle/netclient-mipsle-softfloat main.go && upx -o build/netclient-mipsle/netclient-mipsle-softfloat-upx build/netclient-mipsle/netclient-mipsle-softfloat - name: Upload mipsle to Release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: netclient/build/netclient-mipsle/netclient + file: netclient/build/netclient-mipsle/netclient-mipsle tag: ${{ env.NETMAKER_VERSION }} overwrite: true prerelease: true asset_name: netclient-mipsle + - name: Upload mipsle-upx to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-mipsle/netclient-mipsle-upx + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-mipsle-upx + + - name: Upload mipsle-softfloat to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-mipsle/netclient-mipsle-softfloat + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-mipsle-softfloat + + - name: Upload mipsle-softfloat-upx to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-mipsle/netclient-mipsle-softfloat-upx + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-mipsle-softfloat-upx + netclient-mips: runs-on: ubuntu-latest needs: version @@ -325,29 +356,49 @@ jobs: - name: Build run: | cd netclient - env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -X 'main.version=$NETMAKER_VERSION'" -o build/netclient-mips/netclient main.go - env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags "-s -w -X 'main.version=$NETMAKER_VERSION'" -o build/netclient-mips-upx/netclient main.go && upx build/netclient-mips-upx/netclient + env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags "-s -w -X 'main.version=$NETMAKER_VERSION'" -o build/netclient-mips/netclient-mips main.go && upx -o build/netclient-mips/netclient-mips-upx build/netclient-mips/netclient-mips + env CGO_ENABLED=0 GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-s -w -X 'main.version=$NETMAKER_VERSION'" -o build/netclient-mips/netclient-mips-softfloat main.go && upx -o build/netclient-mips/netclient-mips-softfloat-upx build/netclient-mips/netclient-mips-softfloat - name: Upload mips to Release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: netclient/build/netclient-mips/netclient + file: netclient/build/netclient-mips/netclient-mips tag: ${{ env.NETMAKER_VERSION }} overwrite: true prerelease: true asset_name: netclient-mips - - name: Upload upx compressed version of mips to Release + - name: Upload mips-upx to Release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: netclient/build/netclient-mips-upx/netclient + file: netclient/build/netclient-mips/netclient-mips-upx tag: ${{ env.NETMAKER_VERSION }} overwrite: true prerelease: true asset_name: netclient-mips-upx + - name: Upload netclient-mips-softfloat to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-mips/netclient-mips-softfloat + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-mips-softfloat + + - name: Upload netclient-mips-softfloat-upx to Release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: netclient/build/netclient-mips/netclient-mips-softfloat-upx + tag: ${{ env.NETMAKER_VERSION }} + overwrite: true + prerelease: true + asset_name: netclient-mips-softfloat-upx + netclient-freebsd: runs-on: ubuntu-latest needs: version diff --git a/netclient/bin-maker.sh b/netclient/bin-maker.sh index 05808fa4..e686d7ba 100755 --- a/netclient/bin-maker.sh +++ b/netclient/bin-maker.sh @@ -19,11 +19,15 @@ function build if [ "$_goarch" == "arm" ] && [ "$_goarm" == "" ]; then build $_goarch $_goose 5 && build $_goarch $_goose 6 && build $_goarch $_goose 7 else - echo $_out - if [ "$_goarch" == "mips" ]; then - # If the binary created through `GOMIPS=softfloat GOARCH=mipsle` is not compatible with your hardware, try changing these variables and creating a binary file compatible with your hardware. - GOARM=$_goarm GOMIPS=softfloat GOARCH=mipsle GOOS=$_goose GOHOSTARCH=$__HOST_ARCH CGO_ENABLED=0 go build -ldflags="-X 'main.version=$VERSION'" -o $_out + + if [[ $_goarch == mips* ]]; then + #At present GOMIPS64 based binaries are not generated through this script, more details about GOMIPS environment variables in https://go.dev/doc/asm#mips . + echo $_out-softfloat + GOARM=$_goarm GOMIPS=softfloat GOARCH=$_goarch GOOS=$_goose GOHOSTARCH=$__HOST_ARCH CGO_ENABLED=0 go build -ldflags="-X 'main.version=$VERSION'" -o $_out-softfloat + echo $_out + GOARM=$_goarm GOARCH=$_goarch GOOS=$_goose GOHOSTARCH=$__HOST_ARCH CGO_ENABLED=0 go build -ldflags="-X 'main.version=$VERSION'" -o $_out else + echo $_out GOARM=$_goarm GOARCH=$_goarch GOOS=$_goose GOHOSTARCH=$__HOST_ARCH CGO_ENABLED=0 go build -ldflags="-X 'main.version=$VERSION'" -o $_out fi fi @@ -36,4 +40,3 @@ for arch in ${__freebsd[*]}; do build "$arch" "freebsd"; done for arch in ${__darwin[*]}; do build "$arch" "darwin"; done for arch in ${__windows[*]}; do build "$arch" "windows"; done - diff --git a/scripts/netclient-install.sh b/scripts/netclient-install.sh index 91992ce0..3df02c7b 100755 --- a/scripts/netclient-install.sh +++ b/scripts/netclient-install.sh @@ -151,8 +151,15 @@ case $(uname | tr A-Z a-z) in mipsle) dist=netclient-mipsle ;; - mips*) - dist=netclient-$CPU_ARCH + mips) + #If binary in the below condition is not compatible with your hardware, retry with other netclient-mips* binaries. + if [[ `printf '\0\1' | hexdump -e '/2 "%04x"'` -eq 0100 ]]; then + #Little Endian, tested and confirmed in GL-MT1300 OS "OpenWrt 19.07.8" + dist=netclient-mipsle-softfloat + else + #Big Endian, tested and confirmed in DSL-2750U OS "OpenWrt 22.03.2" + dist=netclient-mips-softfloat + fi ;; *) fatal "$CPU_ARCH : cpu architecture not supported"