Skip to content

Commit

Permalink
Some preliminary support for spiboot for rockpro64
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Jul 3, 2018
1 parent 8e5c6be commit 7c9835c
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ else
LOADER_BIN ?= rkbin/rk33/rk3328_loader_ddr333_v1.08.244.bin
endif
MINILOADER_BIN ?= rkbin/rk33/rk3328_miniloader_v2.44.bin
SPI_BOOT ?= rksd
else ifeq (rockpro64,$(BOARD_TARGET))
ATF_PLAT ?= rk3399
UBOOT_DEFCONFIG ?= rockpro64-rk3399_defconfig
Expand All @@ -35,6 +36,7 @@ BOARD_CHIP ?= rk3399
LOADER_BIN ?= rkbin/rk33/rk3399_loader_v1.10.112_support_1CS.bin
LOADER_RESTART ?= 1
MINILOADER_BIN ?= rkbin/rk33/rk3399_miniloader_v1.12.bin
# SPI_BOOT ?= rkspl # not-yet-supported
else
$(error Unsupported BOARD_TARGET)
endif
Expand Down
92 changes: 67 additions & 25 deletions Makefile.uboot.mk
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
UBOOT_OUTPUT_DIR ?= $(CURDIR)/tmp/u-boot-$(BOARD_TARGET)
UBOOT_LOADER ?= out/u-boot-$(BOARD_TARGET)/idbloader.img
ifeq (rkspl,$(SPI_BOOT))
UBOOT_LOADER_SPL ?= out/u-boot-$(BOARD_TARGET)/idbloader_spl.img
endif
UBOOT_MAKE ?= make -C $(UBOOT_DIR) KBUILD_OUTPUT=$(UBOOT_OUTPUT_DIR) BL31=$(realpath $(BL31)) \
CROSS_COMPILE="ccache aarch64-linux-gnu-"
UBOOT_PACKAGE ?= u-boot-$(BOARD_TARGET)-$(RELEASE_NAME)_all.deb

tmp/u-boot-$(BOARD_TARGET)/.config: $(UBOOT_DIR)/configs/$(UBOOT_DEFCONFIG)
$(UBOOT_MAKE) $(UBOOT_DEFCONFIG)
$(UBOOT_MAKE) $(UBOOT_DEFCONFIG)

$(UBOOT_LOADER): tmp/u-boot-$(BOARD_TARGET)/.config $(BL31)
$(UBOOT_OUTPUT_DIR)/u-boot.itb: tmp/u-boot-$(BOARD_TARGET)/.config $(BL31)
$(UBOOT_MAKE) -j $$(nproc)
$(UBOOT_MAKE) -j $$(nproc) u-boot.itb

$(UBOOT_LOADER): $(UBOOT_OUTPUT_DIR)/u-boot.itb
mkdir -p out/u-boot-$(BOARD_TARGET)
ifneq (,$(USE_UBOOT_SPL))
$(UBOOT_OUTPUT_DIR)/tools/mkimage -n $(BOARD_CHIP) -T rksd -d $(UBOOT_OUTPUT_DIR)/spl/u-boot-spl.bin [email protected]
else ifneq (,$(USE_UBOOT_TPL))
$(UBOOT_OUTPUT_DIR)/tools/mkimage -n $(BOARD_CHIP) -T rksd -d $(UBOOT_OUTPUT_DIR)/tpl/u-boot-tpl.bin [email protected]
cat $(UBOOT_OUTPUT_DIR)/spl/u-boot-spl.bin >> [email protected]
else ifeq (rock64,$(BOARD_TARGET))
$(UBOOT_OUTPUT_DIR)/tools/mkimage -n $(BOARD_CHIP) -T rksd -d $(DDR) [email protected]
cat $(UBOOT_OUTPUT_DIR)/spl/u-boot-spl.bin >> [email protected]
else ifeq (rockpro64,$(BOARD_TARGET))
else ifneq (,$(DDR))
$(UBOOT_OUTPUT_DIR)/tools/mkimage -n $(BOARD_CHIP) -T rksd -d $(DDR) [email protected]
cat $(UBOOT_OUTPUT_DIR)/spl/u-boot-spl.bin >> [email protected]
else
Expand All @@ -29,6 +31,28 @@ endif
dd if=$(UBOOT_OUTPUT_DIR)/u-boot.itb [email protected] seek=$$((0x200-64)) conv=notrunc
mv [email protected] $@

ifeq (,$(UBOOT_LOADER_SPL))
$(UBOOT_LOADER_SPL): $(UBOOT_OUTPUT_DIR)/u-boot.itb
mkdir -p out/u-boot-$(BOARD_TARGET)
ifneq (,$(USE_UBOOT_SPL))
$(UBOOT_OUTPUT_DIR)/tools/mkimage -n $(BOARD_CHIP) -T rkspi -d $(UBOOT_OUTPUT_DIR)/spl/u-boot-spl.bin [email protected]
else ifneq (,$(USE_UBOOT_TPL))
$(UBOOT_OUTPUT_DIR)/tools/mkimage -n $(BOARD_CHIP) -T rkspi -d $(UBOOT_OUTPUT_DIR)/tpl/u-boot-tpl.bin [email protected]
cat $(UBOOT_OUTPUT_DIR)/spl/u-boot-spl.bin >> [email protected]
else ifneq (,$(DDR))
$(UBOOT_OUTPUT_DIR)/tools/mkimage -n $(BOARD_CHIP) -T rkspi -d $(DDR) [email protected]
for i in $$(seq 1 128); do \
dd count=4 && dd of=/dev/zero count=4; \
done < $(UBOOT_OUTPUT_DIR)/spl/u-boot-spl.bin >> [email protected]
else
@echo "Invalid $(BOARD_TARGET)"
@exit 1
endif
ls -al [email protected]
dd if=$(UBOOT_OUTPUT_DIR)/u-boot.itb [email protected] seek=$$((0x200)) conv=notrunc
mv [email protected] $@
endif

.PHONY: u-boot-menuconfig # edit u-boot config and save as defconfig
u-boot-menuconfig:
$(UBOOT_MAKE) ARCH=arm64 $(UBOOT_DEFCONFIG)
Expand All @@ -45,20 +69,7 @@ u-boot-build:
u-boot-clear:
rm -rf $(UBOOT_LOADER)/..

out/u-boot/%/boot.scr: blobs/%.cmd
mkdir -p $$(dirname $@)
mkimage -C none -A arm -T script -d $< $@

out/u-boot/%/boot.img: out/u-boot/%/boot.scr
dd if=/dev/zero of=$@ bs=1M count=2
mkfs.vfat -n "u-boot-script" $@
mcopy -sm -i $@ $< ::

u-boot-%-$(BOARD_TARGET).img: out/u-boot/%/boot.img $(UBOOT_LOADER)
build/mk-image.sh -c $(BOARD_CHIP) -d out/u-boot-$(BOARD_TARGET) -t system -s 128 -b $< -o "$@.tmp"
mv "$@.tmp" $@

$(UBOOT_PACKAGE): u-boot-package $(UBOOT_LOADER)
$(UBOOT_PACKAGE): u-boot-package $(UBOOT_LOADER) $(UBOOT_LOADER_SPL)
fpm -s dir -t deb -n u-boot-$(BOARD_TARGET) -v $(RELEASE_NAME) \
-p $@ \
--deb-priority optional --category admin \
Expand All @@ -76,13 +87,44 @@ $(UBOOT_PACKAGE): u-boot-package $(UBOOT_LOADER)
--vendor "Kamil Trzciński" \
-a all \
u-boot-package/root/=/ \
$(UBOOT_LOADER)=/usr/lib/u-boot-$(BOARD_TARGET)/idbloader.img
$(addsuffix =/usr/lib/u-boot-$(BOARD_TARGET)/,$(UBOOT_LOADER) $(UBOOT_LOADER_SPL))

.PHONY: u-boot-package
u-boot-package: $(UBOOT_PACKAGE)

.PHONY: u-boot-flash-spi-$(BOARD_TARGET)
u-boot-flash-spi-$(BOARD_TARGET): u-boot-flash-spi-$(BOARD_TARGET).img.xz
ifneq (,$(SPI_BOOT))
out/u-boot/%/boot.scr: blobs/%.cmd
mkdir -p $$(dirname $@)
mkimage -C none -A arm -T script -d $< $@

out/u-boot-$(BOARD_TARGET)/%-boot.img: out/u-boot/%/boot.scr $(UBOOT_LOADER) $(UBOOT_LOADER_SPL)
dd if=/dev/zero of=$@.tmp bs=1M count=32
mkfs.vfat -n "u-boot-script" $@.tmp
mcopy -sm -i $@.tmp $< ::
ifneq (,$(UBOOT_LOADER_SPL))
mcopy -sm -i [email protected] $(UBOOT_LOADER_SPL) ::
else
mcopy -sm -i [email protected] $(UBOOT_LOADER) ::
endif
mv [email protected] $@

.PHONY: u-boot-erase-spi-$(BOARD_TARGET)
u-boot-erase-spi-$(BOARD_TARGET): u-boot-erase-spi-$(BOARD_TARGET).img.xz
u-boot-%-$(BOARD_TARGET).img: out/u-boot-$(BOARD_TARGET)/%-boot.img $(UBOOT_LOADER)
build/mk-image.sh -c $(BOARD_CHIP) -d out/u-boot-$(BOARD_TARGET) -t system -s 128 -b $< -o "$@.tmp"
mv "$@.tmp" $@

.PHONY: u-boot-flash-spi
u-boot-flash-spi: u-boot-flash-spi-$(BOARD_TARGET).img.xz

.PHONY: u-boot-erase-spi
u-boot-erase-spi: u-boot-erase-spi-$(BOARD_TARGET).img.xz

else

.PHONY: u-boot-flash-spi
u-boot-flash-spi:
# not-supported

.PHONY: u-boot-erase-spi
u-boot-erase-spi:
# not-supported
endif
12 changes: 6 additions & 6 deletions Makefile.variants.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ linux-$(BOARD_TARGET): \
bionic-$(BOARD_TARGET) \
stretch-$(BOARD_TARGET) \
linux-virtual \
u-boot-flash-spi-$(BOARD_TARGET) \
u-boot-erase-spi-$(BOARD_TARGET)
u-boot-flash-spi \
u-boot-erase-spi

.PHONY: linux-minimal-$(BOARD_TARGET) # build all linux variants
linux-minimal-$(BOARD_TARGET): \
Expand All @@ -42,12 +42,12 @@ linux-minimal-$(BOARD_TARGET): \
stretch-minimal-$(BOARD_TARGET) \
stretch-openmediavault-$(BOARD_TARGET) \
linux-virtual \
u-boot-flash-spi-$(BOARD_TARGET) \
u-boot-erase-spi-$(BOARD_TARGET)
u-boot-flash-spi \
u-boot-erase-spi

.PHONY: linux-packages-$(BOARD_TARGET) # build all packages only
linux-packages-$(BOARD_TARGET): \
linux-virtual \
linux-package \
u-boot-flash-spi-$(BOARD_TARGET) \
u-boot-erase-spi-$(BOARD_TARGET)
u-boot-flash-spi \
u-boot-erase-spi
2 changes: 1 addition & 1 deletion blobs/erase-spi.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ setenv blink_power 'led power off; sleep 0.1; led power on'
# erase flash
run blink_power blink_power
sf probe
sf erase 8000 3e8000
sf erase 0 3f0000

# blink forever
while true; do run blink_power; sleep 1; done
43 changes: 34 additions & 9 deletions blobs/flash-spi.cmd
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
setenv blink_power 'led power off; sleep 0.1; led power on'
setenv blink_standby 'led standby off; sleep 0.1; led standby on'

# first read existing loader
run blink_power
sf probe
${devtype} read ${kernel_addr_r} 40 1f40;

# erase flash
run blink_power blink_power
sf erase 8000 3e8000
# or load idbloader_spl.img and write it to 0 offset of spi
# or load idbloader.img and write it to 0 offset of spi
# or fail badly

# write flash
run blink_power blink_power blink_power
sf write ${kernel_addr_r} 8000 3e8000
if size ${devtype} ${devnum}:${distro_bootpart} idbloader_spl.img; then
load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} idbloader_spl.img

# blink forever
while true; do run blink_power; sleep 1; done
# erase flash
run blink_power blink_power
sf erase 0 3f0000

# write flash
run blink_power blink_power blink_power
sf write ${kernel_addr_r} 0 ${filesize}

# blink forever
while true; do run blink_power; sleep 1; done
elif size ${devtype} ${devnum}:${distro_bootpart} idbloader.img; then
load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} idbloader.img

# erase flash
run blink_power blink_power
sf erase 8000 3e8000

# write flash
run blink_power blink_power blink_power
sf write ${kernel_addr_r} 8000 ${filesize}

# blink forever
while true; do run blink_power; sleep 1; done
else
# blink forever
echo "missing idbloader.img or idbloader_spl.img"
while true; do run blink_standby; sleep 1; done
fi

0 comments on commit 7c9835c

Please sign in to comment.