Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
m01 committed Dec 22, 2017
0 parents commit 303a0b6
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ArchLinuxARM-aarch64-latest.tar.gz
# other repos
arm-trusted-firmware
u-boot
rkbin
# supporting stuff
u-boot-venv
# build
out
arch.img
arch.img.xz

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Michiel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
UBOOT_DEFCONFIG ?= rock64-rk3328_defconfig
UBOOT_DIR ?= u-boot
PYTHON ?= python2

arch.img: sync u-boot-venv ArchLinuxARM-aarch64-latest.tar.gz out/u-boot/idbloader.img
guestfish -N arch.img=disk:2048M -a out/u-boot/idbloader.img --rw -f create.gfs

arch.img.xz: arch.img
xz $<

ArchLinuxARM-aarch64-latest.tar.gz:
curl -LO http://archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz

arm-trusted-firmware:
git clone https://github.com/ARM-software/arm-trusted-firmware.git

u-boot:
# poor man's XML parser ;-)
BRANCH=$$(curl -s https://raw.githubusercontent.com/ayufan-rock64/linux-manifests/default/default.xml | grep linux-u-boot | egrep -o 'revision=\"([^\"]+)\"' | cut -d'"' -f2); \
git clone --branch $$BRANCH https://github.com/ayufan-rock64/linux-u-boot.git u-boot; \
sed -i 's/#!\/usr\/bin.*python[2]*/#!\/usr\/bin\/env python2/' $$(egrep -l '#\!.*python' -r u-boot | grep -v -i README)
# ^ fix interpreter.. but even that's not enough

u-boot-venv:
virtualenv -p python2 u-boot-venv

rkbin:
git clone https://github.com/ayufan-rock64/rkbin.git

sync: rkbin arm-trusted-firmware ArchLinuxARM-aarch64-latest.tar.gz u-boot

clean:
rm -rfv arch.img out

superclean: clean
rm -rf arm-trusted-firmware u-boot rkbin \
ArchLinuxARM-aarch64-latest.tar.gz u-boot-venv

include Makefile.atf.mk
include Makefile.uboot.mk
16 changes: 16 additions & 0 deletions Makefile.atf.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BL31 ?= arm-trusted-firmware/build/rk3328/release/bl31/bl31.elf

arm-trusted-firmware/build/rk3328/release/bl31/bl31.elf: arm-trusted-firmware
make -C $< realclean
make -C $< CROSS_COMPILE=aarch64-linux-gnu- PLAT=rk3328 bl31

arm-trusted-firmware/build/rk3328/debug/bl31/bl31.elf: arm-trusted-firmware
make -C $< realclean
make -C $< CROSS_COMPILE=aarch64-linux-gnu- PLAT=rk3328 bl31 DEBUG=1

.PHONY: atf-build
atf-build: $(BL31)

.PHONY: atf-clean
atf-clean:
rm -rf arm-trusted-firmware/build
64 changes: 64 additions & 0 deletions Makefile.uboot.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
UBOOT_MAKE ?= source $(UBOOT_DIR)/../u-boot-venv/bin/activate; make -C $(UBOOT_DIR) \
CROSS_COMPILE="aarch64-linux-gnu-"

$(UBOOT_DIR)/.config: $(UBOOT_DIR)/configs/$(UBOOT_DEFCONFIG)
$(UBOOT_MAKE) $(UBOOT_DEFCONFIG)

ifneq (,$(FORCE))
.PHONY: out/u-boot/idbloader.img
endif
out/u-boot/idbloader.img: $(UBOOT_DIR)/.config $(BL31) u-boot-venv u-boot
cp -u $(BL31) u-boot/bl31.elf
$(UBOOT_MAKE) -j $$(nproc)
$(UBOOT_MAKE) -j $$(nproc) u-boot.itb
mkdir -p out/u-boot
ifneq (,$(USE_UBOOT_TPL))
$(UBOOT_DIR)/tools/mkimage -n rk3328 -T rksd -d $(UBOOT_DIR)/tpl/u-boot-tpl.bin [email protected]
else
$(UBOOT_DIR)/tools/mkimage -n rk3328 -T rksd -d rkbin/rk33/rk3328_ddr_786MHz_v1.06.bin [email protected]
endif
cat $(UBOOT_DIR)/spl/u-boot-spl.bin >> [email protected]
dd if=$(UBOOT_DIR)/u-boot.itb [email protected] seek=$$((0x200-64)) conv=notrunc
mv [email protected] $@

.PHONY: u-boot-menuconfig # edit u-boot config and save as defconfig
u-boot-menuconfig: u-boot-venv u-boot
$(UBOOT_MAKE) ARCH=arm64 $(UBOOT_DEFCONFIG)
$(UBOOT_MAKE) ARCH=arm64 menuconfig
$(UBOOT_MAKE) ARCH=arm64 savedefconfig
cp $(UBOOT_DIR)/defconfig $(UBOOT_DIR)/configs/$(UBOOT_DEFCONFIG)

.PHONY: u-boot-clear
u-boot-clear:
rm -rf out/u-boot/

.PHONY: u-boot-boot # boot u-boot over USB
u-boot-boot: out/u-boot/idbloader.img
rkdeveloptool db rkbin/rk33/rk3328_loader_v1.08.244_for_spi_nor_build_Aug_7_2017.bin
sleep 1s
rkdeveloptool rid
rkdeveloptool wl 512 $(UBOOT_DIR)/u-boot.itb
rkdeveloptool rd
sleep 1s

cat rkbin/rk33/rk3328_ddr_786MHz_v1.06.bin | openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 | rkflashtool l
cat u-boot/spl/u-boot-spl.bin | openssl rc4 -K 7c4e0304550509072d2c7b38170d1711 | rkflashtool L

.PHONY: u-boot-flash-spi # flash u-boot to SPI
u-boot-flash-spi: out/u-boot/idbloader.img
rkdeveloptool db rkbin/rk33/rk3328_loader_v1.08.244_for_spi_nor_build_Aug_7_2017.bin
sleep 1s
rkdeveloptool rid
rkdeveloptool wl 64 $<
rkdeveloptool rd

.PHONY: u-boot-clear-spi # clear u-boot to SPI
u-boot-clear-spi: out/u-boot/idbloader.img
rkdeveloptool db rkbin/rk33/rk3328_loader_v1.08.244_for_spi_nor_build_Aug_7_2017.bin
sleep 1s
rkdeveloptool rid
rkdeveloptool wl 64 $<
rkdeveloptool rd

.PHONY: u-boot-build # compile u-boot
u-boot-build: out/u-boot/idbloader.img
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Rock64 Arch Linux Image Builder
===============================

Overview
--------
This code will build a pretty "vanilla" Arch Linux ARM image for the Rock64 Single Board Computer.

It builds u-boot using ayufan's scripts (from https://github.com/ayufan-rock64/linux-build/, https://github.com/ayufan-rock64/linux-u-boot/). Then, it use guestfish to create an empty image, partition it as required by the RK3328, format the `boot` and `linux-root` partitions, and extract the [Arch Linux ARM ARMv8 generic](https://archlinuxarm.org/platforms/armv8/generic) tarball into the image. It will then add the u-boot bootloader, extlinux config with the kernel command line args and fix the serial console.

Build procedure
---------------
This is written from the perspective of someone building the image on Arch Linux x86_64.

Install the following prerequisites (mostly required for building u-boot):
* `aarch64-linux-gnu-gcc`
* `guestfish`
* `dtc`
* `git`
* `uboot-tools`
* `swig`
* `make`

Then:
```
make [arch.img]
```

Usage
-----
Burn image to sdcard or eMMC. Boot.

username/password: `alarm`/`alarm`
`root` password: `root`

When using SSH, login as `alarm` first, then `su root`.

Known/potential issues
------------
* If you suffer from network performance issues, [try disabling rx and tx pauses using ethtool](https://github.com/ayufan-rock64/linux-build/blob/master/package/root/etc/network/if-up.d/rock64-offload)

Things to do
------------
In no particular order:

- [ ] Figure out how to install extra packages (currently, guestfish's `command` running ability cannot be used because of the mismatch in architectures in the guest image and host)
- [ ] Create systemd unit file for the ethtool setup (see above)
- [ ] Contribute Arch Linux support back into ayufan's [linux-build](https://github.com/ayufan-rock64/linux-build/) repo, assuming it's desired.
- [ ] Build Arch Linux packages for ayufan's kernels.

Credits
-------
* ayufan for his excellent work on building Rock64 images. Many parts of this repo are inspired by his [linux-build](https://github.com/ayufan-rock64/linux-build/) and other code. The following are (almost) directly taken from his code:
* `extlinux.conf`
* `Makefile.*.mk`
* Rockchip for caring about mainline support for their chips
* Arch Linux ARM for the distribution
* [Arch Linux Wiki page on banana pi](https://wiki.archlinux.org/index.php/Banana_Pi) for a pointer on fixing python library loading issues when building u-boot
57 changes: 57 additions & 0 deletions create.gfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# create partition table
# see:
# - http://opensource.rock-chips.com/wiki_Partitions
# - https://github.com/ayufan-rock64/linux-build/tree/master/build
part-init /dev/sda gpt
part-add /dev/sda p 0x40 0x1f7f
part-set-name /dev/sda 1 loader1
part-add /dev/sda p 0x1f80 0x1fff
part-set-name /dev/sda 2 reserved1
part-add /dev/sda p 0x2000 0x3fff
part-set-name /dev/sda 3 reserved2
part-add /dev/sda p 0x4000 0x5fff
part-set-name /dev/sda 4 loader2
part-add /dev/sda p 0x6000 0x7fff
part-set-name /dev/sda 5 atf
part-add /dev/sda p 0x8000 0x3ffff
part-set-name /dev/sda 6 boot
part-add /dev/sda p 0x40000 -128
# MS Basic Data Partition
part-set-gpt-type /dev/sda 6 EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
# u-boot will filter/scan for bootable partitions
part-set-bootable /dev/sda 6 true

part-set-name /dev/sda 7 linux-root
# set aarch64 root partition type
part-set-gpt-type /dev/sda 7 B921B045-1DF0-41C3-AF44-4C6F280D3FAE

# Format
# NB: We should really be specifying the vfat sector size, but guestfish thinks the -S command is only allowed for mkfs.ufs.
# it looks like 512 is the default anyway though, so I think we're OK: https://github.com/dosfstools/dosfstools/blob/5cdad55563e9efbeacb0413e8a01e4c89727ff5a/src/mkfs.fat.c#L223
# specify file system labels
mkfs vfat /dev/sda6 label:boot
mke2fs /dev/sda7 fstype:ext4 label:linux-root

list-filesystems

# Setup boot, root filesystems
mount /dev/sda7 /
mkdir-p /boot
mount /dev/sda6 /boot
tar-in ArchLinuxARM-aarch64-latest.tar.gz / compress:gzip xattrs:true selinux:true acls:true

upload -<<SECURETTY_EOF /etc/securetty
# Rock64
ttyFIQ0
SECURETTY_EOF
write-append /etc/fstab "LABEL=boot /boot vfat defaults 0 0"

#cp /boot/Image /boot/efi/
#cp /boot/initramfs-linux.img /boot/efi/initrd.img
#cp /boot/dtbs/rockchip/rk3328-rock64.dtb /boot/efi/dtb

mkdir-p /boot/extlinux
copy-in files/extlinux.conf /boot/extlinux

# copy out/u-boot/idbloader.img into loader1 partition at offset 0x40
copy-device-to-device /dev/sdb /dev/sda1
5 changes: 5 additions & 0 deletions files/extlinux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
label kernel-4.14
kernel /Image
initrd /initramfs-linux.img
fdt /dtbs/rockchip/rk3328-rock64.dtb
append earlycon=uart8250,mmio32,0xff130000 rw root=LABEL=linux-root rootwait rootfstype=ext4 coherent_pool=1M ethaddr=${ethaddr} eth1addr=${eth1addr} serial=${serial#}

0 comments on commit 303a0b6

Please sign in to comment.