genode/tool/create_uboot
Martin Stein 2d9d55a6d3 tool: create_uboot
To make the creation of a bootstrap medium for most ARM platforms more
comfortable this tool shall bundle all the different U-Boot source
states, patches, and MMC preparation rules that we gathered over the
year for that purpose. As input, the tool merely needs the targeted
platform (analogous to the platform parameter of 'create_builddir'). By
now, 'hw_wand_quad' is the only supported platform. Further platforms
can be added successively. As output, the tool creates a head image file
of small size (8MiB) that can be copied (dd) with offset 0 to the MMC.

Fixes #1730
2015-10-09 16:36:30 +02:00

122 lines
3.3 KiB
Makefile
Executable File

#!/usr/bin/make -f
#
# \brief Tool for creating an MMC image with a platform specific U-Boot setup
# \author Martin Stein
# \date 2015-09-30
#
#
# Print help text
#
help:
$(ECHO)
$(ECHO) "Tool for creating an MMC image with a platform specific U-Boot setup"
$(ECHO)
$(ECHO) "usage:"
$(ECHO)
$(ECHO) " create_uboot <platform> [BUILD_DIR=<build-dir>]"
$(ECHO)
$(ECHO) " <platform> can be:"
$(ECHO) " 'hw_wand_quad'"
$(ECHO)
$(ECHO) " The image will be located at:"
$(ECHO) " $(UBOOT_BUILD_DIR)<platform>/$(shell basename $(MMC_IMG))"
$(ECHO)
PLATFORMS_ARM := hw_wand_quad
PLATFORMS := $(PLATFORMS_ARM)
# get targeted platform based on the make target
PLATFORM := $(firstword $(filter $(PLATFORMS),$(MAKECMDGOALS)))
# get Genode base directory based on the known location of this tool
GENODE_DIR := $(realpath $(dir $(firstword $(MAKEFILE_LIST)))/..)
UBOOT_URL := https://github.com/m-stein/uboot
UBOOT_DIR := $(GENODE_DIR)/contrib/uboot
UBOOT_TAG := $(UBOOT_DIR)/.gitignore
UBOOT_BRANCH := genode_$(PLATFORM)
UBOOT_BRANCH_TAG := $(UBOOT_DIR)/$(UBOOT_BRANCH)
UBOOT_BUILD_ROOT := $(UBOOT_DIR)/build
UBOOT_BUILD_DIR := $(UBOOT_BUILD_ROOT)/$(PLATFORM)
UBOOT_BUILD_CONF := $(UBOOT_BUILD_DIR)/.config
MMC_IMG := $(UBOOT_BUILD_DIR)/mmc_img
MMC_IMG_SIZE := 8M
SHELL := bash
VERBOSE := @
ECHO := @echo -e
BRIGHT_COL := \033[01;33m
DEFAULT_COL := \033[0m
#
# Determine architecture based on the given platform
#
ifeq ($(filter-out $(PLATFORMS_ARM),$(PLATFORM)),)
ARCH := arm
endif
UBOOT_MAKE := \
$(VERBOSE)make ARCH=$(ARCH) \
CROSS_COMPILE=/usr/local/genode-gcc/bin/genode-$(ARCH)- \
O=$(UBOOT_BUILD_DIR) \
-j4
#
# Platform settings
#
ifeq ($(PLATFORM), hw_wand_quad)
UBOOT_IMG := $(UBOOT_BUILD_DIR)/u-boot.img
UBOOT_IMG_SPL := $(UBOOT_BUILD_DIR)/SPL
UBOOT_IMGS := $(UBOOT_IMG) $(UBOOT_IMG_SPL)
UBOOT_CONF := wandboard_config
FINISH_IMAGE := \
dd if=$(UBOOT_IMG_SPL) of=$(MMC_IMG) bs=1k seek=1 conv=notrunc,fsync; \
dd if=$(UBOOT_IMG) of=$(MMC_IMG) bs=1k seek=69 conv=notrunc,fsync;
endif
#
# Generic rules for the creation of the image
#
$(PLATFORM): $(MMC_IMG)
$(MMC_IMG): $(UBOOT_IMGS)
$(ECHO) "$(BRIGHT_COL)Composing MMC image...$(DEFAULT_COL)"
$(VERBOSE)dd if=/dev/zero of=$(MMC_IMG) bs=$(MMC_IMG_SIZE) seek=1 count=0
$(VERBOSE)$(FINISH_IMAGE)
$(ECHO)
$(ECHO) "Successfully created MMC image."
$(ECHO) "You can install the image on an empty MMC for example via:"
$(ECHO) "sudo dd if=$(MMC_IMG) of=/dev/<YOUR_MMC> conv=fsync"
$(ECHO)
$(UBOOT_IMGS): $(UBOOT_BUILD_CONF) $(UBOOT_DIR)
$(ECHO) "$(BRIGHT_COL)Building U-Boot images...$(DEFAULT_COL)"
$(UBOOT_MAKE) -C $(UBOOT_BUILD_DIR)
$(UBOOT_BUILD_CONF): $(UBOOT_BRANCH_TAG)
$(ECHO) "$(BRIGHT_COL)Building U-Boot config...$(DEFAULT_COL)"
$(VERBOSE)mkdir -p $(UBOOT_BUILD_DIR)
$(UBOOT_MAKE) -C $(UBOOT_DIR) $(UBOOT_CONF)
$(UBOOT_BRANCH_TAG): $(UBOOT_TAG)
$(VERBOSE)git -C $(UBOOT_DIR) checkout $(UBOOT_BRANCH)
$(UBOOT_TAG):
$(ECHO) "$(BRIGHT_COL)Downloading U-Boot sources...$(DEFAULT_COL)"
$(VERBOSE)git clone $(UBOOT_URL) $(UBOOT_DIR)
.PHONY: $(PLATFORM)
#
# Clean-up rules
#
clean:
rm -rf $(UBOOT_BUILD_ROOT)
cleanall:
rm -rf $(UBOOT_DIR)