<commit_before>#!/bin/sh
#
# Simple script to create a disk image which boots to U-Boot on Pine64.
#
# This script uses boot0 binary blob (as extracted from the Pine64 Android
# image) together with a correctly prefixed U-Boot and A DOS partition table
# to create a bootable SDcard image for the Pine64. If a Kernel and DTB is
# found in ../kernel, it is added as well.
#
# U-Boot tree:
# - https://github.com/longsleep/u-boot-pine64/tree/pine64-hacks
#
# Build the U-Boot tree and assemble it with ATF, SCP and FEX and put the
# resulting u-boot-with-dtb.bin file into the ../build directory. The
# u-boot-postprocess script provides an easy way to do all that.
#

set -e

out="$1"
disk_size="$2"
kernel_tarball="$3"
model="$4"

if [ -z "$out" ]; then
	echo "Usage: $0 <image-file.img> [disk size in MiB] [<kernel-tarball>] [<pine64|so|pinebook>]"
	exit 1
fi

if [ -z "$disk_size" ]; then
	disk_size=100 #MiB
fi

if [ "$disk_size" -lt 60 ]; then
	echo "Disk size must be at least 60 MiB"
	exit 2
fi

if [ -z "$model" = "" ]; then
    model="pine64"
fi

echo "Creating $model image $out of size $disk_size MiB ..."

if [ "$model" = "pine64" ]; then
    model=""
fi
suffix=""
if [ -n "$model" ]; then
    suffix="-$model"
fi

if [[ -z "$boot0" ]]; then
  boot0="../blobs/boot0$model.bin"
fi

if [[ -z "$uboot" ]]; then
  uboot="../build/u-boot-with-dtb$suffix.bin"
fi
kernel="../build"

temp=$(mktemp -d)

cleanup() {
	if [ -d "$temp" ]; then
		rm -rf "$temp"
	fi
}
trap cleanup EXIT

if [ -n "$kernel_tarball" -a "$kernel_tarball" != "-" ]; then
	echo "Using Kernel from $kernel_tarball ..."
	tar -C $temp -xJf "$kernel_tarball"
	kernel=$temp/boot
	mv $temp/boot/uEnv.txt.in $temp/boot/uEnv.txt
fi

boot0_position=8      # KiB
uboot_position=19096  # KiB
part_position=20480   # KiB
boot_size=50          # MiB

# Create beginning of disk
dd if=/dev/zero bs=1M count=$((part_position/1024)) of="$out"
dd if="$boot0" conv=notrunc bs=1k seek=$boot0_position of="$out"
dd if="$uboot" conv=notrunc bs=1k seek=$uboot_position of="$out"

# Create boot file system (VFAT)
dd if=/dev/zero bs=1M count=${boot_size} of=${out}1
mkfs.vfat -n BOOT ${out}1

# Add boot support if there
if [ -e "${kernel}/pine64/Image" -a -e "${kernel}/pine64/sun50i-a64-pine64-plus.dtb" ]; then
	mcopy -sm -i ${out}1 ${kernel}/pine64 ::
	mcopy -m -i ${out}1 ${kernel}/initrd.img :: || true
	mcopy -m -i ${out}1 ${kernel}/uEnv.txt :: || true<commit_msg>Fix simpleimage producing empty BOOT<commit_after>#!/bin/sh
#
# Simple script to create a disk image which boots to U-Boot on Pine64.
#
# This script uses boot0 binary blob (as extracted from the Pine64 Android
# image) together with a correctly prefixed U-Boot and A DOS partition table
# to create a bootable SDcard image for the Pine64. If a Kernel and DTB is
# found in ../kernel, it is added as well.
#
# U-Boot tree:
# - https://github.com/longsleep/u-boot-pine64/tree/pine64-hacks
#
# Build the U-Boot tree and assemble it with ATF, SCP and FEX and put the
# resulting u-boot-with-dtb.bin file into the ../build directory. The
# u-boot-postprocess script provides an easy way to do all that.
#

set -e

out="$1"
disk_size="$2"
kernel_tarball="$3"
model="$4"

if [ -z "$out" ]; then
	echo "Usage: $0 <image-file.img> [disk size in MiB] [<kernel-tarball>] [<pine64|so|pinebook>]"
	exit 1
fi

if [ -z "$disk_size" ]; then
	disk_size=100 #MiB
fi

if [ "$disk_size" -lt 60 ]; then
	echo "Disk size must be at least 60 MiB"
	exit 2
fi

if [ -z "$model" = "" ]; then
    model="pine64"
fi

echo "Creating $model image $out of size $disk_size MiB ..."

if [ "$model" = "pine64" ]; then
    model=""
fi
suffix=""
if [ -n "$model" ]; then
    suffix="-$model"
fi

if [[ -z "$boot0" ]]; then
  boot0="../blobs/boot0$model.bin"
fi

if [[ -z "$uboot" ]]; then
  uboot="../build/u-boot-with-dtb$suffix.bin"
fi
kernel="../build"

temp=$(mktemp -d)

cleanup() {
	if [ -d "$temp" ]; then
		rm -rf "$temp"
	fi
}
trap cleanup EXIT

boot0_position=8      # KiB
uboot_position=19096  # KiB
part_position=20480   # KiB
boot_size=50          # MiB

# Create beginning of disk
dd if=/dev/zero bs=1M count=$((part_position/1024)) of="$out"
dd if="$boot0" conv=notrunc bs=1k seek=$boot0_position of="$out"
dd if="$uboot" conv=notrunc bs=1k seek=$uboot_position of="$out"

# Create boot file system (VFAT)
dd if=/dev/zero bs=1M count=${boot_size} of=${out}1
mkfs.vfat -n BOOT ${out}1

# Add boot support if there
if [ -n "$kernel_tarball" ]; then
	echo "Using Kernel from $kernel_tarball ..."
	tar -C $temp -xJf "$kernel_tarball"
	mv $temp/boot/uEnv.txt.in $temp/boot/uEnv.txt
	mcopy -sm -i ${out}1 ${temp}/boot/* ::
elif [ -e "${kernel}/pine64/Image" -a -e "${kernel}/pine64/sun50i-a64-pine64-plus.dtb" ]; then
	mcopy -sm -i ${out}1 ${kernel}/pine64 ::
	mcopy -m -i ${out}1 ${kernel}/initrd.img :: || true
	mcopy -m -i ${out}1 ${kernel}/uEnv.txt :: || true
{'fraction_non_alphanumeric': 0.16810699588477365, 'fraction_numerical': 0.031069958847736626, 'mean_word_length': 3.5729068673565383, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '795469', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1849, 'n_words': 588}