Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 117 additions & 93 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,80 +1,101 @@
# Note: This isn't really a build system
# It's a bunch of command lines encoded
# in a Makefile so I don't have to remember
# multi part processes

BBBUILDROOT=$(shell realpath ./bbbuildroot)
M5BUILDROOT=$(shell realpath ./m5buildroot)
OUTPUTS=$(shell realpath ./outputs/)
BUILDROOT=$(BBBUILDROOT)/buildroot

.PHONY: toolchain \
buildroot \
buildroot_m5 \
uboot \
uboot_m5 \
linux \
upload \
outputsdir \
kernel_m5.fit \
kernel_breadbee.fit \
rtk \
squeekyclean
PWD = $(shell pwd)
OUTPUTS=$(shell realpath $(PWD)/outputs/)
LINUXROOT=$(shell realpath $(PWD)/linux)
LINUX_CONFIG=$(LINUXROOT)/.config
LINUX_IMAGE=$(LINUXROOT)/arch/arm/boot/zImage
UBOOTROOT=$(shell realpath $(PWD)/u-boot)
MSTARBLOBSROOT=$(shell realpath $(PWD)/mstarblobs)
VENDOR_FIT=$(OUTPUTS)/dev_vendor.fit
LINUX_ARGS=ARCH=arm -j8 CROSS_COMPILE=$(CROSS_COMPILE)

CROSS_COMPILE=arm-buildroot-linux-gnueabihf-
BBBUILDROOT=$(shell realpath $(PWD)/bbbuildroot)
BB_TOOLCHAIN=$(BBBUILDROOT)/buildroot/output/host
BB_UBOOT=$(OUTPUTS)/dev_u-boot.img
BB_SPL=$(OUTPUTS)/spl
BB_KERNEL=$(OUTPUTS)/dev_kernel_breadbee.fit

all: toolchain nor_ipl spl_padded
M5BUILDROOT=$(shell realpath $(PWD)/m5buildroot)
M5_TOOLCHAIN=$(M5BUILDROOT)/buildroot/output/host
M5_UBOOT=$(OUTPUTS)/dev_m5_u-boot.img
M5_SPL=$(OUTPUTS)/spl_m5
M5_KERNEL=$(OUTPUTS)/dev_kernel_m5.fit

outputsdir:
mkdir -p $(OUTPUTS)
M5_BOOTSTRAP_STAMP=.stamped_m5_bootstrap
BB_BOOTSTRAP_STAMP=.stamped_bb_boostrap

DEFAULT_BRANCH_LINUX=mstar_dev_v5_8_rebase_cleanup
DEFAULT_BRANCH_UBOOT=m5iplwork

M5_LINUX_STAMP=.stamped_m5_linux
BB_LINUX_STAMP=.stamped_bb_linux

OWNER=mbilloo

.PHONY: breadbee \
m5 \
squeakyclean \
superclean

CROSS_COMPILE=arm-buildroot-linux-gnueabihf-

# We have two copies of build root here:
# one is the breadbee version with the bits it needs
# the other is the m5 version that is basically stock.
all: nor_ipl spl_padded

buildroot:
$(BBBUILDROOT):
git clone git@github.com:$(OWNER)/breadbee_buildroot.git $(BBBUILDROOT)

$(BB_TOOLCHAIN): $(BBBUILDROOT) $(BB_BOOTSTRAP_STAMP)
$(MAKE) -C $(BBBUILDROOT)

buildroot_m5:
$(MAKE) -C $(M5BUILDROOT)
# We might want a generic rootfs to embed into a kernel,
# so copy that into the outputs dir
cp $(M5BUILDROOT)/buildroot/output/images/rootfs.cpio $(OUTPUTS)/m5_rootfs.cpio
$(M5BUILDROOT):
git clone git@github.com:$(OWNER)/buildroot_mercury5.git $(M5BUILDROOT)

toolchain:
if [ ! -e $(BUILDROOT)/output/host/bin/arm-buildroot-linux-gnueabihf-gcc ]; then \
$(MAKE) buildroot; \
fi
$(M5_TOOLCHAIN): $(M5BUILDROOT) $(M5_BOOTSTRAP_STAMP)
$(MAKE) -C $(M5BUILDROOT)

outputsdir:
$(OUTPUTS):
mkdir -p $(OUTPUTS)

$(MSTARBLOBSROOT):
git clone git@github.com:fifteenhex/mstarblobs.git

DEFAULT_BRANCH_LINUX=mstar_dev_v5_8_rebase_cleanup
DEFAULT_BRANCH_UBOOT=m5iplwork

bootstrap:
git clone git@github.com:fifteenhex/linux.git
git -C linux checkout --track origin/$(DEFAULT_BRANCH_LINUX)
cp linux.config linux/.config
git clone git@github.com:breadbee/u-boot.git
git -C u-boot checkout --track origin/$(DEFAULT_BRANCH_UBOOT)
git clone git@github.com:breadbee/breadbee_buildroot.git $(BBBUILDROOT)
$(BB_BOOTSTRAP_STAMP): $(LINUXROOT) $(UBOOTROOT) $(BBBUILDROOT) $(MSTARBLOBSROOT) $(M5BUILDROOT)
$(MAKE) -C $(BBBUILDROOT) bootstrap
git clone git@github.com:fifteenhex/mstarblobs.git
touch $@

git clone git@github.com:fifteenhex/buildroot_mercury5.git $(M5BUILDROOT)
$(M5_BOOTSTRAP_STAMP): $(M5STARBLOBSROOT) $(M5BUILDROOT)
$(MAKE) -C $(M5BUILDROOT) bootstrap
touch $@

LINUX_ARGS=ARCH=arm -j8 CROSS_COMPILE=$(CROSS_COMPILE)
linux:
- rm linux/arch/arm/boot/zImage
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
$(UBOOTROOT):
git clone git@github.com:breadbee/u-boot.git
git -C u-boot checkout --track origin/$(DEFAULT_BRANCH_UBOOT)

$(LINUXROOT):
git clone git@github.com:$(OWNER)/linux.git
git -C linux checkout --track origin/$(DEFAULT_BRANCH_LINUX)

$(LINUX_CONFIG): $(LINUXROOT)
cp linux.config $@

$(BB_LINUX_STAMP): $(BB_TOOLCHAIN) $(LINUX_CONFIG)
PATH=$(BB_TOOLCHAIN)/bin:$$PATH \
$(MAKE) -C linux DTC_FLAGS=--symbols \
$(LINUX_ARGS) \
zImage dtbs
touch $@

$(M5_LINUX_STAMP): $(M5_TOOLCHAIN) $(LINUX_CONFIG)
PATH=$(M5_TOOLCHAIN)/bin:$$PATH \
$(MAKE) -C linux DTC_FLAGS=--symbols \
$(LINUX_ARGS) \
zImage dtbs
# these are for booting with the old mstar u-boot that can't load a dtb
#cat linux/arch/arm/boot/zImage linux/arch/arm/boot/dts/msc313d-mc400l.dtb > \
# $(OUTPUTS)/zImage.msc313d
touch $@

linux_config:
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
Expand All @@ -84,29 +105,29 @@ linux_clean:
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
$(MAKE) -C linux $(LINUX_ARGS) clean

uboot: toolchain outputsdir
$(BB_UBOOT): $(BB_TOOLCHAIN) $(OUTPUTS) $(UBOOTROOT)
$(MAKE) -C u-boot clean
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
PATH=$(BB_TOOLCHAIN)/bin:$$PATH \
$(MAKE) -C u-boot msc313_breadbee_defconfig
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
$(MAKE) -C u-boot CROSS_COMPILE=$(CROSS_COMPILE) -j8
cp u-boot/u-boot.img $(OUTPUTS)/dev_u-boot.img
PATH=$(BB_TOOLCHAIN)/bin:$$PATH \
$(MAKE) -C u-boot CROSS_COMPILE=$(CROSS_COMPILE)
cp u-boot/u-boot.img $@

uboot_m5: toolchain outputsdir
$(M5_UBOOT): $(M5_TOOLCHAIN) $(OUTPUTS) $(UBOOTROOT)
$(MAKE) -C u-boot clean
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
PATH=$(M5_TOOLCHAIN)/bin:$$PATH \
$(MAKE) -C u-boot mercury5_defconfig
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
$(MAKE) -C u-boot CROSS_COMPILE=$(CROSS_COMPILE) -j8
cp u-boot/u-boot.img $(OUTPUTS)/dev_m5_u-boot.img
PATH=$(M5_TOOLCHAIN)/bin:$$PATH \
$(MAKE) -C u-boot CROSS_COMPILE=$(CROSS_COMPILE)
cp u-boot/u-boot.img $@

uboot_clean:
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
uboot_clean: $(BB_TOOLCHAIN)
PATH=$(BB_TOOLCHAIN)/bin:$$PATH \
$(MAKE) -C u-boot clean

# this is to upload the resulting binaries to a tftp server to load on the
# target
upload: linux uboot kernel_breadbee.fit
upload: linux uboot kernel.fit
scp outputs/dev_kernel_breadbee.fit tftp:/srv/tftp/dev_kernel_breadbee.fit
# scp linux/arch/arm/boot/zImage.msc313e tftp:/srv/tftp/zImage.msc313e
# scp linux/arch/arm/boot/dts/infinity3-msc313e-breadbee.dtb tftp:/srv/tftp/msc313e-breadbee.dtb
Expand All @@ -117,63 +138,58 @@ upload: linux uboot kernel_breadbee.fit
# scp buildroot/output/images/rootfs.squashfs tftp:/srv/tftp/rootfs.msc313e


spl: uboot
$(BB_SPL): $(BB_UBOOT)
python3 u-boot/board/thingyjp/breadbee/fix_ipl_hdr.py \
-i u-boot/spl/u-boot-spl.bin \
-o $(OUTPUTS)/spl
-o $@

spl_m5: uboot_m5
$(M5_SPL): $(M5_UBOOT)
python3 u-boot/board/thingyjp/breadbee/fix_ipl_hdr.py \
-i u-boot/spl/u-boot-spl.bin \
-o $(OUTPUTS)/spl_m5
-o $@

# this is a nor sized image (because flashrom doesn't support writing partial images)
# that starts with the mstar IPL
nor_ipl: uboot kernel_breadbee.fit spl_padded
nor_ipl: uboot kernel.fit spl_padded
rm -f nor_ipl
dd if=/dev/zero ibs=1M count=16 | tr "\000" "\377" > nor_ipl
##dd conv=notrunc if=IPL.bin of=nor_ipl bs=1k seek=16
dd conv=notrunc if=ipl_ddr3.bin of=nor_ipl bs=1k seek=16
dd conv=notrunc if=spl_padded of=nor_ipl bs=1k seek=64
dd conv=notrunc if=u-boot/u-boot.img of=nor_ipl bs=1k seek=128
dd conv=notrunc if=kernel_breadbee.fit of=nor_ipl bs=1k seek=512
dd conv=notrunc if=kernel.fit of=nor_ipl bs=1k seek=512

# this is a nor sized image that starts with the u-boot SPL. This will require the
# SPL do the DDR setup etc.
nor: uboot
nor: uboot kernel.fit
rm -f nor
dd if=/dev/zero ibs=1M count=16 | tr "\000" "\377" > nor
dd conv=notrunc if=u-boot/spl/u-boot-spl.bin of=nor bs=1k seek=16
dd conv=notrunc if=u-boot/u-boot.img of=nor bs=1k seek=128

# This builds a FIT image with the kernel and right device tree for m5
kernel_m5.fit: buildroot_m5 outputsdir linux
mkimage -f kernel_m5.its kernel_m5.fit
cp $@ $(OUTPUTS)/dev_$@
# this builds a FIT image with the kernel and the right device trees. This
# should be used with the new u-boot.
$(M5_KERNEL): $(M5_TOOLCHAIN) $(OUTPUTS) $(M5_LINUX_STAMP)
PATH=$(M5_TOOLCHAIN)/bin:$$PATH \
mkimage -f kernel_m5.its $@

$(BB_KERNEL): $(BB_TOOLCHAIN) $(OUTPUTS) $(BB_LINUX_STAMP)
PATH=$(BB_TOOLCHAIN)/bin:$$PATH \
mkimage -f kernel_breadbee.its $@

# This builds a FIT image with the kernel and the right device trees for breadbee.
kernel_breadbee.fit: outputsdir linux
mkimage -f kernel_breadbee.its kernel_breadbee.fit
cp $@ $(OUTPUTS)/dev_$@
$(VENDOR_FIT): $(OUTPUTS)
mkimage -f vendor.its $@

# This builds kernel image with the DTB appended to the end for the ssd201htv2 with
# vendor u-boot
kernel_ssd201htv2: outputsdir linux buildroot_m5
kernel_ssd201htv2: $(OUTPUTS) $(LINUX_IMAGE)
cat linux/arch/arm/boot/zImage linux/arch/arm/boot/dts/infinity2m-ssd202-ssd201htv2.dtb > \
$(OUTPUTS)/$@

clean: linux_clean
rm -rf kernel_m5.fit kernel_breadbee.fit nor nor_ipl
rm -rf kernel.fit nor nor_ipl

push_linux_config:
cp linux/.config ../breadbee_buildroot/br2breadbee/board/thingyjp/breadbee/linux.config

push_linux_m5_config:
PATH=$(BUILDROOT)/output/host/bin:$$PATH \
$(MAKE) -C linux DTC_FLAGS=--symbols \
ARCH=arm -j8 CROSS_COMPILE=$(CROSS_COMPILE) savedefconfig
cp linux/defconfig $(M5BUILDROOT)/br2midrive08/board/70mai/midrive08/linux.config

fix_brick:
sudo flashrom --programmer ch341a_spi -w nor_ipl -l /media/junk/hardware/breadbee/flashrom_layout -i ipl_uboot_spl -N
sudo flashrom --programmer ch341a_spi -w nor_ipl -l /media/junk/hardware/breadbee/flashrom_layout -i uboot -N
Expand All @@ -182,13 +198,21 @@ fix_brick_spl:
sudo flashrom --programmer ch341a_spi -w nor -l /media/junk/hardware/breadbee/flashrom_layout -i ipl_uboot_spl -N
sudo flashrom --programmer ch341a_spi -w nor -l /media/junk/hardware/breadbee/flashrom_layout -i uboot -N

rtk: uboot_m5
RTKPADBYTES=512

m5: $(M5_UBOOT) $(M5_SPL) $(M5_KERNEL)
cp u-boot/u-boot.bin $(OUTPUTS)/rtk

breadbee: $(BB_UBOOT) $(BB_SPL) $(BB_KERNEL)

squeekyclean:
$(MAKE) -C $(BBBUILDROOT) clean

copy_kernel_to_sd: kernel_m5.fit
superclean:
git clean -fxd
rm -fr $(BBBUILDROOT) $(M5BUILDROOT) $(LINUXROOT) $(UBOOTROOT) $(OUTPUTS) $(MSTARBLOBSROOT)

copy_kernel_to_sd: $(M5_KERNEL)
sudo mount /dev/sdc1 /mnt
- sudo cp outputs/dev_kernel_m5.fit /mnt/kernel.fit
sudo umount /mnt
Expand Down
64 changes: 11 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,21 @@
This is a janky environment to manage building u-boot and kernel images so you can quickly
hack on u-boot or the kernel and test your work.

## Getting started

To get started you need to checkout this repo and then populate it with the u-boot, kernel
and buildroot sources by running the bootstrap target:

```
make bootstrap
```

Once this is complete any of the targets below should build. Note that the first build will
take a long time as the toolchain and rootfs build will be triggered. Subsequent builds will
reuse the toolchain and rootfs and will be much faster.

## Targets

### rtk
### breadbee

This is a special target that is not for the breadbee at all. Instead this is for development
using a mercury5 device. The m5 IPL looks for a file called ```rtk``` (real time kernel?) on
the first FAT partition, loads it to DRAM and jumps into it. We can exploit this to load u-boot
into DRAM and start it.

This can be useful because the infinity3 (breadbee Soc) and mercury5 are very similar but the
mercury5 supports booting u-boot from SD card so it's a lot easier to work with than flashing
the SPI NOR each time.
This is the target for the breadbee. It will generate all of the appropriate artifacts.

```
make rtk
make breadbee
```
### m5

### spl

This builds the u-boot SPL, pads it and fixes up the image checksum so it can be loaded from
the IPL.
This is the target for the dash cam used for development, until the breadbee HW is available

```
make spl
```

### kernel_m5.fit

This builds a kernel FIT image *without* the breadbee overlays but *with* the breadbee rescue initramfs.
This is mainly for testing on mercury5 where actually writing the rootfs to the SPI NOR would
destroy the existing firmware that is still useful for making sure the screen etc are still working.

```
make kernel_m5.fit
```

### kernel_breadbee.fit

This builds a kernel FIT image *with* the breadbee overlays and *without* any built in initramfs.
This is mainly for TFTP booting on a breadbee to test kernel changes with the rootfs already
being on SPI NOR.

```
make kernel_breadbee.fit
make m5
```

### kernel_ssd201htv2
Expand Down Expand Up @@ -91,14 +49,14 @@ setenv serverip 192.168.3.1; setenv loadaddr 0x22000000; dhcp kernel.fit.breadbe
```

# booting the kernel from sd card
```fatload mmc 0:1 $loadaddr kernel.fit; bootm $loadaddr#mirrorcam```

## mercury5 midrive d08

```fatload mmc 0:1 $loadaddr kernel.fit; bootm $loadaddr#midrive08```
# Booting the uboot + kernel fit RTK image

## mercury5 mirror cam
- copy the rtk file to your SD card
- wait until you get the uboot prompt
- type ```bootm 0x20048000#midrive08``` and hit enter

```fatload mmc 0:1 $loadaddr kernel.fit; bootm $loadaddr#mirrorcam```

# Replacing u-boot

Expand Down