Browse Source

Merge pull request #19 from sarnold/starfive

Makefile updates for "normal" image build
Drew Fustini 3 years ago
parent
commit
d3d0c189fe
3 changed files with 123 additions and 66 deletions
  1. 51 38
      Makefile
  2. 67 27
      README.md
  3. 5 1
      build.sh

+ 51 - 38
Makefile

@@ -13,10 +13,10 @@ buildroot_initramfs_wrkdir := $(wrkdir)/buildroot_initramfs
 
 # TODO: make RISCV be able to be set to alternate toolchain path
 RISCV ?= $(buildroot_initramfs_wrkdir)/host
-RVPATH := $(RISCV)/bin:$(PATH)
-target := riscv64-buildroot-linux-gnu
+RVPATH ?= $(RISCV)/bin:/usr/sbin:/sbin:$(PATH)
+target ?= riscv64-buildroot-linux-gnu
 
-CROSS_COMPILE := $(RISCV)/bin/$(target)-
+CROSS_COMPILE ?= $(RISCV)/bin/$(target)-
 
 buildroot_initramfs_tar := $(buildroot_initramfs_wrkdir)/images/rootfs.tar
 buildroot_initramfs_config := $(confdir)/buildroot_initramfs_config
@@ -82,7 +82,7 @@ endif
 uboot_defconfig := $(uboot_srcdir)/configs/$(uboot_config)
 rootfs := $(wrkdir)/rootfs.bin
 
-target_gcc := $(CROSS_COMPILE)gcc
+target_gcc ?= $(CROSS_COMPILE)gcc
 
 .PHONY: all nvdla-demo
 nvdla-demo: $(fit) $(vfat_image)
@@ -158,22 +158,22 @@ $(buildroot_initramfs_sysroot_stamp): $(buildroot_initramfs_tar)
 $(linux_wrkdir)/.config: $(linux_defconfig) $(linux_srcdir)
 	mkdir -p $(dir $@)
 	cp -p $< $@
-	$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
+	$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig
 ifeq (,$(filter rv%c,$(ISA)))
 	sed 's/^.*CONFIG_RISCV_ISA_C.*$$/CONFIG_RISCV_ISA_C=n/' -i $@
-	$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
+	$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig
 endif
 ifeq ($(ISA),$(filter rv32%,$(ISA)))
 	sed 's/^.*CONFIG_ARCH_RV32I.*$$/CONFIG_ARCH_RV32I=y/' -i $@
 	sed 's/^.*CONFIG_ARCH_RV64I.*$$/CONFIG_ARCH_RV64I=n/' -i $@
-	$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv olddefconfig
+	$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig
 endif
 
 $(uboot_wrkdir)/.config: $(uboot_defconfig)
 	mkdir -p $(dir $@)
 	cp -p $< $@
 
-$(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(target_gcc)
+$(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(target_gcc) $(buildroot_initramfs_sysroot)
 	$(MAKE) -C $< O=$(linux_wrkdir) \
 		ARCH=riscv \
 		CROSS_COMPILE=$(CROSS_COMPILE) \
@@ -181,6 +181,12 @@ $(vmlinux): $(linux_srcdir) $(linux_wrkdir)/.config $(target_gcc)
 		vmlinux		\
 		all \
 		modules
+	$(MAKE) -C $< O=$(linux_wrkdir) \
+		ARCH=riscv \
+		CROSS_COMPILE=$(CROSS_COMPILE) \
+		PATH=$(RVPATH) \
+		INSTALL_MOD_PATH=$(buildroot_initramfs_sysroot) \
+		modules_install
 
 .PHONY: initrd
 initrd: $(initramfs)
@@ -203,8 +209,8 @@ $(vmlinux_bin): $(vmlinux)
 
 .PHONY: linux-menuconfig
 linux-menuconfig: $(linux_wrkdir)/.config
-	$(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv menuconfig
-	$(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv savedefconfig
+	$(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
+	$(MAKE) -C $(linux_srcdir) O=$(dir $<) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) savedefconfig
 	cp $(dir $<)defconfig $(linux_defconfig)
 
 sbi: $(uboot) $(vmlinux)
@@ -254,14 +260,14 @@ $(qemu): $(qemu_srcdir)
 
 .PHONY: uboot-menuconfig
 uboot-menuconfig: $(uboot_wrkdir)/.config
-	$(MAKE) -C $(uboot_srcdir) O=$(dir $<) ARCH=riscv menuconfig
+	$(MAKE) -C $(uboot_srcdir) O=$(dir $<) ARCH=riscv CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
 	cp $(uboot_wrkdir)/.config $(uboot_defconfig)
 
 $(uboot): $(uboot_srcdir) $(target_gcc)
 	rm -rf $(uboot_wrkdir)
 	mkdir -p $(uboot_wrkdir)
 	mkdir -p $(dir $@)
-	$(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) $(uboot_config)
+	$(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE) $(uboot_config)
 	$(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE)
 
 $(rootfs): $(buildroot_rootfs_ext)
@@ -307,6 +313,12 @@ qemu-rootfs: $(qemu) $(bbl) $(vmlinux) $(initramfs) $(rootfs)
 .PHONY: uboot
 uboot: $(uboot)
 
+# disk tools
+MKFS_VFAT ?= mkfs.vfat
+MKFS_EXT4 ?= mkfs.ext4
+PARTPROBE ?= partprobe
+SGDISK ?= sgdisk
+
 # Relevant partition type codes
 BBL		= 2E54B353-1271-4842-806F-E436D6AF6985
 VFAT            = EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
@@ -333,7 +345,7 @@ $(vfat_image): $(fit) $(confdir)/u74_uEnv.txt
 		echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
 		rm $(flash_image); exit 1; fi
 	dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
-	/sbin/mkfs.vfat $(vfat_image)
+	$(MKFS_VFAT) $(vfat_image)
 	PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
 	PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/u74_uEnv.txt ::u74_uEnv.txt
 else
@@ -352,13 +364,13 @@ $(vfat_image): $(fit) $(confdir)/uEnv.txt
 		echo "Uboot is too large for partition!!\nReduce uboot or increase partition size"; \
 		rm $(flash_image); exit 1; fi
 	dd if=/dev/zero of=$(vfat_image) bs=512 count=$(VFAT_SIZE)
-	/sbin/mkfs.vfat $(vfat_image)
+	$(MKFS_VFAT) $(vfat_image)
 	PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(fit) ::hifiveu.fit
 	PATH=$(RVPATH) MTOOLS_SKIP_CHECK=1 mcopy -i $(vfat_image) $(confdir)/uEnv.txt ::uEnv.txt
 endif
 $(flash_image): $(uboot) $(fit) $(vfat_image)
 	dd if=/dev/zero of=$(flash_image) bs=1M count=32
-	/sbin/sgdisk --clear -g  \
+	$(SGDISK) --clear -g  \
 		--new=1:$(VFAT_START):$(VFAT_END)  --change-name=1:"Vfat Boot"	--typecode=1:$(VFAT)   \
 		--new=2:$(UBOOT_START):$(UBOOT_END)   --change-name=2:uboot	--typecode=2:$(UBOOT) \
 		--new=3:$(UENV_START):$(UENV_END)   --change-name=3:uboot-env	--typecode=3:$(UBOOTENV) \
@@ -370,7 +382,7 @@ DEMO_END=11718750
 
 #$(demo_image): $(uboot) $(fit) $(vfat_image) $(ext_image)
 #	dd if=/dev/zero of=$(flash_image) bs=512 count=$(DEMO_END)
-#	/sbin/sgdisk --clear  \
+#	$(SGDISK) --clear -g \
 #		--new=1:$(VFAT_START):$(VFAT_END)  --change-name=1:"Vfat Boot"	--typecode=1:$(VFAT)   \
 #		--new=3:$(UBOOT_START):$(UBOOT_END)   --change-name=3:uboot	--typecode=3:$(UBOOT) \
 #		--new=2:264192:$(DEMO_END) --change-name=2:root	--typecode=2:$(LINUX) \
@@ -382,13 +394,13 @@ DEMO_END=11718750
 .PHONY: format-boot-loader
 format-boot-loader: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
 	@test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
-	/sbin/sgdisk --clear -g \
+	$(SGDISK) --clear -g  \
 		--new=1:$(VFAT_START):$(VFAT_END)  --change-name=1:"Vfat Boot"	--typecode=1:$(VFAT)   \
 		--new=2:$(UBOOT_START):$(UBOOT_END)   --change-name=2:uboot	--typecode=2:$(UBOOT) \
 		--new=3:$(UENV_START):$(UENV_END)  --change-name=3:uboot-env	--typecode=3:$(UBOOTENV) \
 		--new=4:274432:0 --change-name=4:root	--typecode=4:$(LINUX) \
 		$(DISK)
-	-/sbin/partprobe
+	-$(PARTPROBE)
 	@sleep 1
 ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
 	@$(eval PART1 := $(DISK)p1)
@@ -419,7 +431,7 @@ format-rootfs-image: format-boot-loader
 	@echo "Done setting up basic initramfs boot. We will now try to install"
 	@echo "a Debian snapshot to the Linux partition, which requires sudo"
 	@echo "you can safely cancel here"
-	/sbin/mke2fs -t ext4 $(PART4)
+	$(MKFS_EXT4) $(PART4)
 	-mkdir -p tmp-mnt
 	-mkdir -p tmp-rootfs
 	-sudo mount $(PART4) tmp-mnt && \
@@ -431,27 +443,28 @@ format-demo-image: format-boot-loader
 	@echo "Done setting up basic initramfs boot. We will now try to install"
 	@echo "a Debian snapshot to the Linux partition, which requires sudo"
 	@echo "you can safely cancel here"
-	/sbin/mke2fs -t ext4 $(PART4)
+	$(MKFS_EXT4) $(PART4)
 	-mkdir tmp-mnt
 	-sudo mount $(PART4) tmp-mnt && cd tmp-mnt && \
 		sudo wget $(DEMO_URL)$(DEMO_IMAGE) && \
-		sudo tar -Jxvf $(DEMO_IMAGE)
+		sudo tar -xvpf $(DEMO_IMAGE)
 	sudo umount tmp-mnt
 
+# default size: 16GB
+DISK_IMAGE_SIZE ?= 16
 ROOT_BEGIN=272384
-# default size: 20GB
-ROOT_CLUSTER_NUM=$(shell echo $$((20*1024*1024*1024/512)))
+ROOT_CLUSTER_NUM=$(shell echo $$(($(DISK_IMAGE_SIZE)*1024*1024*1024/512)))
 ROOT_END=$(shell echo $$(($(ROOT_BEGIN)+$(ROOT_CLUSTER_NUM))))
 
 format-nvdla-disk: $(bbl_bin) $(uboot) $(fit) $(vfat_image)
 	@test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
-	/sbin/sgdisk --clear -g  \
+	sudo $(SGDISK) --clear -g \
 		--new=1:$(VFAT_START):$(VFAT_END)  --change-name=1:"Vfat Boot"  --typecode=1:$(VFAT)   \
 		--new=2:$(UBOOT_START):$(UBOOT_END)   --change-name=2:uboot --typecode=2:$(UBOOT) \
 		--new=3:$(ROOT_BEGIN):0 --change-name=3:root  --typecode=3:$(LINUX) \
 		$(DISK)
-	-/sbin/partprobe
-	@sleep 1
+	-$(PARTPROBE)
+	@sleep 3
 ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
 	@$(eval PART1 := $(DISK)p1)
 	@$(eval PART2 := $(DISK)p2)
@@ -468,19 +481,19 @@ else
 	@echo Error: Could not find bootloader partition for $(DISK)
 	@exit 1
 endif
-	dd if=$(uboot) of=$(PART2) bs=4096
-	dd if=$(vfat_image) of=$(PART1) bs=4096
+	sudo dd if=$(uboot) of=$(PART2) bs=4096
+	sudo dd if=$(vfat_image) of=$(PART1) bs=4096
 
 #usb config
 
 format-usb-disk: sbi $(uboot) $(fit) $(vfat_image)
 	@test -b $(DISK) || (echo "$(DISK): is not a block device"; exit 1)
-	/sbin/sgdisk --clear -g \
+	sudo $(SGDISK) --clear -g \
 	--new=1:0:+256M  --change-name=1:"Vfat Boot"  --typecode=1:$(VFAT)   \
 	--new=2:0:+1G   --change-name=2:uboot --typecode=2:$(UBOOT) -g\
 	$(DISK)
-	-/sbin/partprobe
-	@sleep 1
+	-$(PARTPROBE)
+	@sleep 3
 ifeq ($(DISK)p1,$(wildcard $(DISK)p1))
 	@$(eval PART1 := $(DISK)p1)
 	@$(eval PART2 := $(DISK)p2)
@@ -497,8 +510,8 @@ else
 	@echo Error: Could not find bootloader partition for $(DISK)
 	@exit 1
 endif
-	dd if=$(uboot) of=$(PART2) bs=4096
-	dd if=$(vfat_image) of=$(PART1) bs=4096
+	sudo dd if=$(uboot) of=$(PART2) bs=4096
+	sudo dd if=$(vfat_image) of=$(PART1) bs=4096
 
 DEB_IMAGE := debian_nvdla_20190506.tar.xz
 DEB_URL := https://github.com/sifive/freedom-u-sdk/releases/download/nvdla-demo-0.1
@@ -507,7 +520,7 @@ format-nvdla-rootfs: format-nvdla-disk
 	@echo "Done setting up basic initramfs boot. We will now try to install"
 	@echo "a Debian snapshot to the Linux partition, which requires sudo"
 	@echo "you can safely cancel here"
-	/sbin/mke2fs -t ext4 $(PART3)
+	sudo $(MKFS_EXT4) $(PART3)
 	-mkdir -p tmp-mnt
 	-mkdir -p tmp-rootfs
 	-sudo mount $(PART3) tmp-mnt && \
@@ -521,11 +534,11 @@ format-nvdla-root: format-nvdla-disk
 	@echo "a Debian snapshot to the Linux partition, which requires sudo"
 	@echo "you can safely cancel here"
 	@test -e $(wrkdir)/$(DEB_IMAGE) || (wget -P $(wrkdir) $(DEB_URL)/$(DEB_IMAGE))
-	/sbin/mke2fs -t ext4 $(PART3)
+	sudo $(MKFS_EXT4) $(PART3)
 	-mkdir -p tmp-mnt
-	-mount $(PART3) tmp-mnt && \
+	-sudo mount $(PART3) tmp-mnt && \
 		echo "please wait until checkpoint reaches 489k" && \
-		tar Jxf $(wrkdir)/$(DEB_IMAGE) -C tmp-mnt --checkpoint=1000
-	umount tmp-mnt
+		sudo tar xpf $(wrkdir)/$(DEB_IMAGE) -C tmp-mnt --checkpoint=1000
+	sudo umount tmp-mnt
 
 -include $(initramfs).d

+ 67 - 27
README.md

@@ -5,7 +5,7 @@ image with a OpenSBI binary, linux kernel, device tree, ramdisk and rootdisk for
 
 ## Prerequisites ##
 
-Recommend OS: Ubuntu 16.04/18.04 
+Recommend OS: Ubuntu 16.04/18.04
 
 After installing the operating system.
 Do not forget updating all packages
@@ -15,7 +15,7 @@ Do not forget updating all packages
 
 Install required additional packages.
 
-	$sudo apt-get install autoconf automake autotools-dev bc bison \
+	$ sudo apt-get install autoconf automake autotools-dev bc bison xxd \
 	build-essential curl flex gawk gdisk git gperf libgmp-dev \
 	libmpc-dev libmpfr-dev libncurses-dev libssl-dev libtool \
 	patchutils python screen texinfo unzip zlib1g-dev device-tree-compiler
@@ -28,47 +28,87 @@ submodules using:
 	$ git submodule update --init --recursive
 
 This will take some time and require around 7GB of disk space. Some modules may
-fail because certain dependencies don't have the best git hosting. 
+fail because certain dependencies don't have the best git hosting.
 
-Once the submodules are initialized, 4 modules`buildroot`,`HiFive_U-boot`,`linux` and `opensbi` need checkout to starfive branch manually.
+Once the submodules are initialized, 4 submodules `buildroot`, `HiFive_U-boot`,
+`linux` and `opensbi` need checkout to starfive branch manually.
 
 After update submodules, run `make` or `make -jx` and the complete toolchain and
 fw_payload.bin.out & image.fit will be built. The completed build tree will consume about 18G of
 disk space.
 
-Copy file  fw_payload.bin.out and image.fit to installation path to use
+Copy files fw_payload.bin.out and image.fit to tftp installation path to use
+
+	Path:
+	freelight-u-sdk/work/image.fit
+	freelight-u-sdk/work/opensbi/platform/starfive/vic7100/firmware/fw_payload.bin.out
+
+## SDCard Image ##
+
+If you don't already use a local tftp server, then you probably want to make
+the sdcard target; the default size is 16 GBs. NOTE THIS WILL DESTROY ALL
+EXISTING DATA on the target sdcard; make sure you know the correct disk,
+eg, with the lsblk command::
+
+    $ lsblk
+    NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
+    sda           8:0    0 465.8G  0 disk 
+    ├─sda1        8:1    0     2M  0 part 
+    ├─sda2        8:2    0   128M  0 part 
+    ├─sda3        8:3    0  1000M  0 part [SWAP]
+    └─sda4        8:4    0 464.7G  0 part /
+    sr0          11:0    1  1024M  0 rom  
+    mmcblk0     179:0    0   3.6G  0 disk 
+    ├─mmcblk0p1 179:1    0   130M  0 part 
+    ├─mmcblk0p2 179:2    0     1M  0 part 
+    └─mmcblk0p3 179:3    0   3.5G  0 part 
+
+you would use the `/dev/mmcblk0` (whole disk) target. Note the build output
+above is only a small initramfs, so the rootfs partition on the card is not
+formatted yet. You will need an sdcard at least 1G (or larger if you want
+to add a full rootfs).  Make sure the sdcard is inserted and you have the
+correct device before you run the `make` command below. Then run something
+like:
+
+    $ make DISK_IMAGE_SIZE=4 DISK=/dev/mmcblk0 format-nvdla-disk
+
+to generate a 4 GB sdcard. Currently you need to boot it manually from the
+u-boot prompt:
+
+    BeagleV # fatload mmc 0 ${ramdisk_addr_r} hifiveu.fit
+    (wait for loading)
+    BeagleV # bootm ${ramdisk_addr_r}
+
 
-	Path:  
-	/freelight-u-sdk/work/image.fit
-	/freelight-u-sdk/work/opensbi/platform/starfive/vic7100/firmware/fw_payload.bin.out
-        
 ## Running on BeagleV ##
 
-After the BeagleV™ is properly connected to the serial port cable, network cable and power cord,turn on the power from the wall power socket to power on the BeagleV™ and you will see the startup information as follows:
+After the BeagleV™ is properly connected to the serial port cable, network cable and power cord turn on the power from the wall power socket to power on the BeagleV™ and you will see the startup information as follows:
 
-	bootloader version: 210209-4547a8d 
-	ddr 0x00000000, 1M test 
-	ddr 0x00100000, 2M test 
-	DDR clk 2133M,Version: 210302-5aea32f 
+	bootloader version: 210209-4547a8d
+	ddr 0x00000000, 1M test
+	ddr 0x00100000, 2M test
+	DDR clk 2133M,Version: 210302-5aea32f
 	2
 Press any key as soon as it starts up to enter the **upgrade menu**. In this menu, you can update uboot
 
-	bootloader version: 210209-4547a8d 
-	ddr 0x00000000, 1M test 
-	ddr 0x00100000, 2M test 
-	DDR clk 2133M,Version: 210302-5aea32f 
-	0 
-	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
-	xxxxxxxxxxxFLASH PROGRAMMINGxxxxxxxxx 
-	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
-
-	0:update boot 
-	1: quit 
+	bootloader version: 210209-4547a8d
+	ddr 0x00000000, 1M test
+	ddr 0x00100000, 2M test
+	DDR clk 2133M,Version: 210302-5aea32f
+	0
+	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+	xxxxxxxxxxxFLASH PROGRAMMINGxxxxxxxxx
+	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
+	0:update boot
+	1: quit
 	select the function:
 
-Type **"0"**  to update the uboot file fw_payload.bin.out via Xmodem mode, and then Type **"1"** to exit Flash Programming.
+Type **"0"**  to update the uboot file fw_payload.bin.out via Xmodem mode,
+and then Type **"1"** to exit Flash Programming.
 
-After you will see the information `StarFive #`,select the installation path and install image.fit through TFTP:
+After you will see the information `StarFive #`,select the installation path
+and install image.fit through TFTP:
 
 	setenv fileaddr a0000000; setenv serverip 192.168.xxx.xxx;tftpboot ${fileaddr}  ${serverip}:image.fit;bootm start ${fileaddr};bootm loados ${fileaddr};booti 0x80200000 0x86100000:${filesize} 0x86000000
 

+ 5 - 1
build.sh

@@ -8,4 +8,8 @@ make distclean || true
 git submodule sync
 git submodule update --recursive --init
 
-make -j${CORES}
+make MKFS_VFAT="/sbin/mkfs.vfat" \
+    MKFS_EXT4="/sbin/mkfs.ext4" \
+    PARTPROBE="/sbin/partprobe" \
+    SGDISK="/sbin/sgdisk" \
+    -j${CORES}