From 2c89ef57d1aca4560b191317a78a5a311d0285d7 Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Sat, 6 Mar 2021 20:19:11 +0900 Subject: [PATCH 1/2] Brainux for x1 --- .github/workflows/build.yml | 111 ++++++++++++++++++++++++++++++++++++ .gitmodules | 3 + Makefile | 44 +++++++++++--- README.md | 39 +++++++++---- boot4u | 1 + image/build_image_x1.sh | 51 +++++++++++++++++ linux-brain | 2 +- nkbin_maker | 1 - os-brainux/setup_brainux.sh | 1 + tools/getcross | 36 ++++++++++++ u-boot-brain | 2 +- 11 files changed, 269 insertions(+), 22 deletions(-) create mode 160000 boot4u create mode 100755 image/build_image_x1.sh delete mode 160000 nkbin_maker create mode 100755 tools/getcross diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a2488ee..4d1a71d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,6 +87,41 @@ jobs: asset_name: listconfig asset_content_type: text/plain + build-linux-x1: + runs-on: ubuntu-20.04 + needs: [create_release] + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Workaround for apt update failure + run: sudo rm /etc/apt/sources.list.d/github_git-lfs.* + - name: Install deps + run: sudo apt update && sudo apt install build-essential bison flex libncurses5-dev gcc-arm-linux-gnueabihf libssl-dev lzop qemu-user-static debootstrap + - name: Configure for Linux + run: make ldefconfig-x1 + - name: Build Linux + run: make lbuild + - name: Setup releases + id: release_name + run: | + mkdir release + cp ./linux-brain/arch/arm/boot/dts/imx7ulp-pwh*.dtb release/ + cp ./linux-brain/arch/arm/boot/zImage release/zImage + zip -r release.zip release/ + - name: Generate archive name + id: archive_name + run: echo ::set-output name=name::linux-x1-${GITHUB_REF/refs\/*s\//} + - name: Upload release.zip + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: release.zip + asset_name: ${{ steps.archive_name.outputs.name }}.zip + asset_content_type: application/zip + build-uboot: runs-on: ubuntu-20.04 needs: [create_release] @@ -145,6 +180,45 @@ jobs: asset_name: ${{ steps.archive_name.outputs.name }}.zip asset_content_type: application/zip + build-uboot-x1: + runs-on: ubuntu-20.04 + needs: [create_release] + strategy: + matrix: + include: + - model: h1 + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Workaround for apt update failure + run: sudo rm /etc/apt/sources.list.d/github_git-lfs.* + - name: Install deps + run: sudo apt update && sudo apt install build-essential bison flex libncurses5-dev gcc-arm-linux-gnueabihf libssl-dev lzop qemu-user-static debootstrap + - name: Configure for U-Boot + run: make udefconfig-${{ matrix.model }} + - name: Build U-Boot + run: make ubuild + - name: Setup releases + id: release_name + run: | + mkdir release + cp ./u-boot-brain/u-boot.bin release/u-boot.bin + zip -r release.zip release/ + - name: Generate archive name + id: archive_name + run: echo ::set-output name=name::uboot-${{ matrix.model }}-${GITHUB_REF/refs\/*s\//} + - name: Upload release.zip + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: release.zip + asset_name: ${{ steps.archive_name.outputs.name }}.zip + asset_content_type: application/zip + build-sd: runs-on: ubuntu-20.04 needs: [create_release] @@ -181,3 +255,40 @@ jobs: asset_name: ${{ steps.image_name.outputs.name }}.zip asset_content_type: application/zip + build-sd-x1: + runs-on: ubuntu-20.04 + needs: [create_release] + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - name: Workaround for apt update failure + run: sudo rm /etc/apt/sources.list.d/github_git-lfs.* + - name: Install deps + run: sudo apt update && sudo apt install kpartx build-essential bison flex libncurses5-dev gcc-arm-linux-gnueabihf libssl-dev lzop qemu-user-static debootstrap + - name: Configure for U-Boot + run: make udefconfig-x1 + - name: Build U-Boot + run: make ubuild + - name: Configure for Linux + run: make ldefconfig-x1 + - name: Build Linux + run: make lbuild + - name: Build Debian Root + run: make brainux + - name: Generate image name + id: image_name + run: echo ::set-output name=name::sdimage-x1-${GITHUB_REF/refs\/*s\//} + - name: Build SD image + run: make image/sd_x1.img && mv image/sd_x1.img ${{ steps.image_name.outputs.name }}.img + - name: Compress + run: zip ${{ steps.image_name.outputs.name }}.zip ${{ steps.image_name.outputs.name }}.img + - name: Upload the image + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ${{ steps.image_name.outputs.name }}.zip + asset_name: ${{ steps.image_name.outputs.name }}.zip + asset_content_type: application/zip diff --git a/.gitmodules b/.gitmodules index 4c94f47..172f02e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "nkbin_maker"] path = nkbin_maker url = https://github.com/brain-hackers/nkbin_maker.git +[submodule "boot4u"] + path = boot4u + url = https://github.com/brain-hackers/boot4u diff --git a/Makefile b/Makefile index 3cfb9e5..50fa849 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ JOBS=$(shell grep -c '^processor' /proc/cpuinfo) +UBOOT_CROSS=$(shell ./tools/getcross u-boot) +LINUX_CROSS=$(shell ./tools/getcross linux) +ROOTFS_CROSS=$(shell ./tools/getcross rootfs) export ARCH=arm -export CROSS_COMPILE=arm-linux-gnueabi- .PHONY: setup: @@ -33,11 +35,11 @@ udefconfig-%: .PHONY: usavedefconfig: - make -C ./u-boot-brain savedefconfig + make CROSS_COMPILE=$(UBOOT_CROSS) -C ./u-boot-brain savedefconfig .PHONY: umenuconfig: - make -C ./u-boot-brain menuconfig + make CROSS_COMPILE=$(UBOOT_CROSS) -C ./u-boot-brain menuconfig .PHONY: uclean: @@ -45,28 +47,41 @@ uclean: .PHONY: ubuild: - make -j$(JOBS) -C ./u-boot-brain u-boot.sb + if [ "$(UBOOT_CROSS)" = "arm-linux-gnueabi-" ]; then \ + make CROSS_COMPILE=$(UBOOT_CROSS) -j$(JOBS) -C ./u-boot-brain u-boot.sb; \ + else \ + make CROSS_COMPILE=$(UBOOT_CROSS) -j$(JOBS) -C ./u-boot-brain u-boot.imx; \ + fi .PHONY: ldefconfig: make -C ./linux-brain brain_defconfig +.PHONY: +ldefconfig-x1: + make -C ./linux-brain imx_v7_defconfig + .PHONY: lmenuconfig: - make -C ./linux-brain menuconfig + make CROSS_COMPILE=$(LINUX_CROSS) -C ./linux-brain menuconfig .PHONY: lsavedefconfig: - make -C ./linux-brain savedefconfig + make CROSS_COMPILE=$(LINUX_CROSS) -C ./linux-brain savedefconfig mv ./linux-brain/defconfig ./linux-brain/arch/arm/configs/brain_defconfig +.PHONY: +lsavedefconfig-x1: + make CROSS_COMPILE=$(LINUX_CROSS) -C ./linux-brain savedefconfig + mv ./linux-brain/defconfig ./linux-brain/arch/arm/configs/imx_v7_defconfig + .PHONY: lclean: make -C ./linux-brain distclean .PHONY: lbuild: - make -j$(JOBS) -C ./linux-brain + make CROSS_COMPILE=$(LINUX_CROSS) -j$(JOBS) -C ./linux-brain .PHONY: ldebpkg: @@ -104,6 +119,14 @@ nkbin-maker: nk.bin: ./nkbin_maker/bsd-ce ./u-boot-brain/u-boot.bin +.PHONY: +boot4ubuild: + make -C ./boot4u + +.PHONY: +boot4uclean: + make -C ./boot4u clean + brainux: @if [ "$(shell uname)" != "Linux" ]; then \ echo "Debootstrap is only available in Linux!"; \ @@ -112,9 +135,9 @@ brainux: sudo mkdir -p brainux @if [ "$(CI)" = "true" ]; then \ echo "I'm in CI and debootstrap without cache."; \ - sudo debootstrap --arch=armel --foreign bullseye brainux/; \ + sudo debootstrap --arch=$(ROOTFS_CROSS) --foreign buster brainux/; \ else \ - sudo debootstrap --arch=armel --foreign bullseye brainux/ http://localhost:65432/debian/; \ + sudo debootstrap --arch=$(ROOTFS_CROSS) --foreign buster brainux/ http://localhost:65432/debian/; \ fi sudo cp /usr/bin/qemu-arm-static brainux/usr/bin/ sudo cp ./os-brainux/setup_brainux.sh brainux/ @@ -125,6 +148,9 @@ brainux: image/sd.img: clean_work ./image/build_image.sh +image/sd_x1.img: clean_work + ./image/build_image_x1.sh + .PHONY: clean_work: sudo rm -rf image/work diff --git a/README.md b/README.md index 52375c5..9156072 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ buildbrain This repository includes: - - linux-brain, u-boot-brain and nkbin_maker as submodules + - linux-brain, u-boot-brain, nkbin_maker and boot4u as submodules - Useful build targets in Makefile - r3build.toml to watch changes that occur in submodules @@ -21,7 +21,8 @@ Getting Started 1. Install dependencies. ``` - $ sudo apt install build-essential bison flex libncurses5-dev gcc-arm-linux-gnueabi qemu-user-static debootstrap kpartx + $ sudo apt install build-essential bison flex libncurses5-dev gcc-arm-linux-gnueabi gcc-arm-linux-gnueabihf libssl-dev bc lzop qemu-user-static debootstrap kpartx + $ pip install pyelftools ``` 1. Clone this repository with recursive clone enabled. @@ -42,34 +43,47 @@ Getting Started - Put `uuu` where the PATH executable points to. -Build and inject U-Boot +Build U-Boot ----------------------- 1. Run `make udefconfig-sh*` to generate `.config`. - For Sx1: `make udefconfig-sh1` - For Sx6: `make udefconfig-sh6` + - For x1: `make udefconfig-h1` -2. Run `make ubuild` to build whole repository and generate `u-boot.sb`. +2. Run `make ubuild` to build whole repository and generate `u-boot.sb` or `u-boot.bin`. - i.MX283 loads a packed U-Boot executable called `u-boot.sb`. -3. To inject the executable into i.MX283 in recovery mode, run `make uuu`. +Inject U-Boot into i.MX283 in recovery mode +----------------------- +1. Follow `Build U-Boot` procedure to make U-Boot binary. + +1. Run `make uuu` Build and make NK.bin ----------------------- -1. Run `make udefconfig` to generate `.config`. +1. Follow `Build U-Boot` procedure to make U-Boot binary. -2. Run `make ubuild` to build whole repository and generate `u-boot.bin`. +1. Run `make nkbin-maker`. -3. Run `make nkbin-maker`. - -4. To make `nk.bin`, run `make nk.bin`. +1. To make `nk.bin`, run `make nk.bin`. - nkbin_maker packs `u-boot.bin` into `nk.bin`. +Build and deploy boot4u +----------------------- + +1. Run `make boot4u` + +1. Create index.din and copy AppMain.bin + - `mkdir /path/to/your/sd/1st/partition/App/boot4u` + - `touch /path/to/your/sd/1st/partition/App/boot4u/index.din` + - `cp boot4u/AppMain.bin /path/to/your/sd/1st/partition/App/boot4u/` + Build Linux ----------- @@ -94,6 +108,11 @@ Bootstrap Debian 11 (bullseye) 1. Confirm that `image/sd.img` is built and burn it to an SD card. +Known issues +---------------------------------------- +If you using gcc 10 for host compiler, `make ubuild` may fail. +To complete build, open `/u-boot-brain/scripts/dtc/dtc-lexer.lex.c` or `/u-boot-brain/scripts/dtc/dtc-parser.tab.c` then comment out `YYLTYPE yylloc;` + Watch changes in submodules & auto-build ---------------------------------------- diff --git a/boot4u b/boot4u new file mode 160000 index 0000000..3f916a0 --- /dev/null +++ b/boot4u @@ -0,0 +1 @@ +Subproject commit 3f916a0cf7b2516e3eaa720a5c77efbe53527eeb diff --git a/image/build_image_x1.sh b/image/build_image_x1.sh new file mode 100755 index 0000000..8afadb2 --- /dev/null +++ b/image/build_image_x1.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -uex -o pipefail + +JOBS=$(nproc) +REPO=$(git rev-parse --show-toplevel) +WORK=${REPO}/image/work +LINUX=${REPO}/linux-brain +IMG=${REPO}/image/sd.img + +mkdir -p ${WORK} + +dd if=/dev/zero of=${IMG} bs=1M count=3072 + +START1=2048 +SECTORS1=$((1024 * 1024 * 64 / 512)) +START2=$((2048 + ${SECTORS1})) + +cat < ${WORK}/part.sfdisk +${IMG}1 : start=${START1}, size=${SECTORS1}, type=b +${IMG}2 : start=${START2}, type=83 +EOF + +sfdisk ${IMG} < ${WORK}/part.sfdisk + +sudo kpartx -av ${IMG} + +LOOPDEV=$(losetup -l | grep sd.img | grep -o 'loop.') + +sudo mkfs.fat -F32 -v -I /dev/mapper/${LOOPDEV}p1 +sudo mkfs.ext4 /dev/mapper/${LOOPDEV}p2 + +mkdir -p ${WORK}/p1 ${WORK}/p2 +sudo mount /dev/mapper/${LOOPDEV}p1 ${WORK}/p1 +sudo mount /dev/mapper/${LOOPDEV}p2 ${WORK}/p2 + +sudo cp ${LINUX}/arch/arm/boot/zImage ${WORK}/p1/ +sudo cp ${LINUX}/arch/arm/boot/dts/imx7ulp-pwh*.dtb ${WORK}/p1/ + +sudo cp ${REPO}/u-boot-brain/u-boot.bin ${WORK}/p1/ + +mkdir -p ${WORK}/p1/App/boot4u +sudo cp ${REPO}/boot4u/AppMain.bin ${WORK}/p1/App/boot4u/ +sudo touch ${WORK}/p1/App/boot4u/index.din + +sudo cp -ra ${REPO}/brainux/* ${WORK}/p2/ + +sudo umount ${WORK}/p1 ${WORK}/p2 +sudo kpartx -d ${IMG} + +rmdir ${WORK}/p1 ${WORK}/p2 + diff --git a/linux-brain b/linux-brain index 7738c0a..fff05ee 160000 --- a/linux-brain +++ b/linux-brain @@ -1 +1 @@ -Subproject commit 7738c0a9cea5981cee2ec4519e14bbd4c0787a95 +Subproject commit fff05eea6877c4a93f1c289aa7ca11feb824389d diff --git a/nkbin_maker b/nkbin_maker deleted file mode 160000 index 4a97a4e..0000000 --- a/nkbin_maker +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4a97a4e8074cec12ac8989bcfcab9b9f7d47156d diff --git a/os-brainux/setup_brainux.sh b/os-brainux/setup_brainux.sh index 3f919e4..2bd82ad 100755 --- a/os-brainux/setup_brainux.sh +++ b/os-brainux/setup_brainux.sh @@ -102,6 +102,7 @@ usermod -a -G video user # Allow root login via UART cat <> /etc/securetty ttymxc0 +ttyLP0 EOF # Get wild diff --git a/tools/getcross b/tools/getcross new file mode 100755 index 0000000..0857a4f --- /dev/null +++ b/tools/getcross @@ -0,0 +1,36 @@ +#!/bin/sh +set -e + +uboot() { + . ./u-boot-brain/.config + case "${CONFIG_SYS_CPU}" in + arm926ejs) echo -n "arm-linux-gnueabi-"; return;; + armv7) echo -n "arm-linux-gnueabihf-"; return;; + *) exit 1;; + esac +} + +linux() { + . ./linux-brain/.config + case "${CONFIG_CPU_ARM926T}_${CONFIG_ARCH_MULTI_V7}" in + y_) echo -n "arm-linux-gnueabi-"; return;; + _y) echo -n "arm-linux-gnueabihf-"; return;; + *) exit 1;; + esac +} + +rootfs() { + . ./linux-brain/.config + case "${CONFIG_CPU_ARM926T}_${CONFIG_ARCH_MULTI_V7}" in + y_) echo -n "armel"; return;; + _y) echo -n "armhf"; return;; + *) exit 1;; + esac +} + +case "$1" in + u-boot) uboot ;; + linux) linux ;; + rootfs) rootfs ;; + *) exit 1; ;; +esac diff --git a/u-boot-brain b/u-boot-brain index 6390f0e..4a52b35 160000 --- a/u-boot-brain +++ b/u-boot-brain @@ -1 +1 @@ -Subproject commit 6390f0ed58a25b770523c81d8b1064fb4b556910 +Subproject commit 4a52b35110e9017fdf2b608dbed3805750098463 From 0ecb9895ac704277c5c82929430130e1a3ba167a Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Tue, 7 Dec 2021 23:55:46 +0900 Subject: [PATCH 2/2] Update linux-brain and u-boot-brain --- linux-brain | 2 +- u-boot-brain | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-brain b/linux-brain index fff05ee..30f2bc6 160000 --- a/linux-brain +++ b/linux-brain @@ -1 +1 @@ -Subproject commit fff05eea6877c4a93f1c289aa7ca11feb824389d +Subproject commit 30f2bc6cf91c74c53192c58324981bd4ed446b06 diff --git a/u-boot-brain b/u-boot-brain index 4a52b35..2fe0c77 160000 --- a/u-boot-brain +++ b/u-boot-brain @@ -1 +1 @@ -Subproject commit 4a52b35110e9017fdf2b608dbed3805750098463 +Subproject commit 2fe0c77400cba01a12ebfdfe04584dc7f438465b