Commit 42027de1 authored by Ronny Nilsson's avatar Ronny Nilsson

sdk: WIP initial support for having rootfs in a block device.

Also take the time to refactor image generation. Customer can
easily add their own image build rules on top of Iopsys.
parent d2901e8e
......@@ -9,6 +9,8 @@ MKFS_DEVTABLE_OPT = -D $(CURDIR)/device_table.txt
include $(TOPDIR)/
include $(INCLUDE_DIR)/
include $(INCLUDE_DIR)/
include $(IOPSYS_FEED_TARGETS)/shared/
# DSL is now part of the filename
......@@ -46,6 +48,7 @@ UBIFS_OPTS = -v -c $$(($(CONFIG_TARGET_NAND_DEVSZ) / $(CONFIG_TARGET_NAND_BLOCKS
-x zlib --squash-uids --devtable=$(CURDIR)/device_table.txt
SQUASHFSOPT += -noI -mem 512M -root-owned -noappend
#Production Image Parameters
......@@ -596,6 +599,10 @@ define Image/Build
# which CONFIG_TARGET_ROOTFS_* are enabled in the configuration.
echo "In Image/Build $(1) $(2)"
$(call Iopsys/Image/$(1),$(1))
$(call Image/Build/$(1),$(1))
# Customer image generation. Here you can add to or
# modify the Iopsys default. Each *.mk is executed
# in lexical order.
# Iopsys default rootfs.
$(KDIR)/blkdev.img:: $(KDIR)/root.squashfs
@echo "Adding Iopsys rootfs to block device image."
# Add Iopsys essential rootfs into the image.
$(call gpt_insert_blob, $(KDIR)/root.squashfs, root0, $@)
$(call gpt_insert_blob, $(KDIR)/root.squashfs, root1, $@)
# Customer image generation. Here you can add to or
# modify the Iopsys default. Each *.mk is executed
# in lexical order.
#@echo "Adding example data to block device image."
# Generate binary blob. Can be a filesystem or whatever.
#cp -vf my-data.bin $(KDIR)/example.bin
# Insert blob in image according to the partition
# table. Ensure to customize the label/name!
#$(call gpt_insert_blob, $(KDIR)/example.bin, example1, $@)
This directory contains Makefiles for custom generation of block device
firmware images. All *.mk are executed by Make in lexical order at
build time. You can easily add you own file to either override or
complement the Iopsys defaults. For example, to add a custom data
partition in the block device (which Iopsys will never touch):
1) cp
2) Edit with your custom labels. (Read
the comments in the file.)
3) Also add a disk partition in blkdev-ptable.d/
Note: only add new files to override Iopsys default! Don't modify
existing files or you will get conflicts next SDK upgrade.
# Iopsys basic definitions for the block device GPT.
unit: sectors
label: gpt
label-id: e9e80691-011d-471f-9c7b-98a15b3a43d1
# Iopsys reserved area for possible future use.
name=reserved0 size=4MiB
# Iopsys default storage of factory calibration data.
name=factory size=1MiB uuid=4f529a15-b76f-4a65-8d22-2845a3bfdecf
# Iopsys essential bootloader partitions. Two "banks" are used.
name=boot0 size=16MiB type=bc13c2ff-59e6-4262-a352-b275fd6f7172 uuid=ca7f09e0-2591-4b80-98b9-b9464302e4e5
name=boot1 size=16MiB type=bc13c2ff-59e6-4262-a352-b275fd6f7172 uuid=cb871e19-213e-4b37-83f2-326715a6bd47
# Iopsys essential rootfs. Two "banks" are used.
# Partition types from
name=root0 size=1024MiB type=69dad710-2ce4-4e3c-b16c-21a1d49abed3 uuid=9486478f-7e15-4256-bc0d-6d0c9fbd1000
name=root1 size=1024MiB type=69dad710-2ce4-4e3c-b16c-21a1d49abed3 uuid=d879bd33-7610-4d98-b004-58b9d9497001
# Example of how to create a new custom partition. Iopsys
# will leave this alone. Any access are from your custom
# application only.
# Partition types from
# A partition named "example" of size 128 kBytes.
#name=example1 size=128KiB uuid=61e3ed5a-f926-4a1e-ac26-43623a80e173
This directory contains specifications for how to partition
the system flash block device (like eMMC).
All *.sfdisk files are joined in lexical order at build time
and feed to the sfdisk program (which in turn creates a GPT).
Iopsys provide a base of necessary partitions. These must not
be removed! They can however be overridden almost as one like.
For example, to expand the root filesystem;
1) cp 20-iopsys-rootfs.sfdisk 21-my-rootfs.sfdisk
2) Edit 21-my-rootfs.sfdisk according to your needs.
Then build as usual. Your new file will override the one from Iopsys.
One can also add custom new partitions which the OS will leave alone.
Note: only add new custom files to override Iopsys default! Don't
modify existing files or you will get conflicts next SDK upgrade.
Advice: Inspect the file "blkdev-ptable.txt" after build to ensure
everything became correct.
# Copyright (C) Iopsys AB
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
MAKECMDGOALS = dummy # nullify stupid OpenWrt .SILENT rule in
include $(TOPDIR)/
include $(wildcard $(IOPSYS_FEED_TARGETS)/shared/lib-*.mk)
export KDIR := $(KDIR)
define Iopsys/Image/ext4
# Invoke THIS file as a standard Make target.
# Minimize the OpenWrt $(call) madness.
$(MAKE) -f $(IOPSYS_FEED_TARGETS)/shared/ $(KDIR)/blkdev.img
define Iopsys/Image/squashfs
# Invoke THIS file as a standard Make target.
# Minimize the OpenWrt $(call) madness.
$(MAKE) -f $(IOPSYS_FEED_TARGETS)/shared/ $(KDIR)/blkdev.img
# Override OpenWrt generation of squashfs due to bad hardcoded options.
define Image/mkfs/squashfs
$(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
# Iopsys raw block device image. Customers can add or
# modify it via subsequent operations in overlay-blkdev-make.d/
# dependencies must be added all at once due to double-colon rule.
blkdev-deps += $(wildcard blkdev-ptable.d/*.sfdisk)
blkdev-deps += $(wildcard blkdev-make.d/*.mk)
blkdev-deps += $(wildcard $(IOPSYS_FEED_TARGETS)/shared/*)
blkdev-deps += Makefile
$(KDIR)/blkdev.img:: $(blkdev-deps)
@echo "Creating block device image"
# Create an empty file which will become our image.
# It MUST be of same size as the block device and
# it SHOULD use all-ones for empty areas.
dd if=/dev/zero bs=1M count=$$((1024 * 4)) | tr "\000" "\377" >"$@"
# Create a GPT in the image according to all concatenated
# specifications in overlay-blkdev-ptable.d/
source "$(IOPSYS_FEED_TARGETS)/shared/" && \
cat blkdev-ptable.d/*.sfdisk | obey_customer_overrides | \
sfdisk --no-tell-kernel --no-reread "$@"
sfdisk -d --no-tell-kernel --no-reread "$@" >"$(KDIR)/blkdev-ptable.txt"
# Customer overlays can add or modify the Iopsys default image.
# Must be last in file!
include $(sort $(wildcard blkdev-make.d/*.mk))
# Library functions for woring with GPT.
# Return the partition start sector.
gpt_part_start = \
sfdisk --no-tell-kernel --no-reread -d $(strip $(1)) | \
grep "name=\"$(strip $(2))\"" | grep -Eo "start=[^,]+" | \
grep -Eo "[[:digit:]]+"
# Return the partition size (in sectors).
gpt_part_size = \
sfdisk --no-tell-kernel --no-reread -d $(strip $(1)) | \
grep "$(strip $(2))" | grep -Eo "size=[^,]+" | \
grep -Eo "[[:digit:]]+"
# Insert (actually overwrite) a blob into a block device
# image according to the already present GPT.
gpt_insert_blob = \
dd if=$(strip $(1)) bs=128k \
seek=$$(( $$( $(call gpt_part_start, $@, $(2)) ) * 512)) \
conv=notrunc,nocreat oflag=seek_bytes of=$(strip $(3))
# Library functions for woring with GPT.
# Find sfdisk duplicates and print line numbers
# of all entries execept the last one.
duplicates_to_sed() {
local line no
while read -t 5 -s line; do
[ -n "$line" ] || continue
for no in $(grep -n "$line" "$1" | cut -d : -f 1 | head -n -1); do
echo -n "${no}d;"
# Read all partitition table specifictation and remove
# entries which has been overriden.
obey_customer_overrides() {
cat - >"${TMPDIR}/ptable-orig.sfdisk"
grep -Eo "^name=[^[:space:]]+" "${TMPDIR}/ptable-orig.sfdisk" | \
sort | uniq -d | duplicates_to_sed "${TMPDIR}/ptable-orig.sfdisk" | \
sed -f - "${TMPDIR}/ptable-orig.sfdisk"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment