Skip to content
Permalink
Browse files

scripts sync to openwrt

  • Loading branch information
zyxmon committed Jan 6, 2020
1 parent b74f37f commit 90426b97cc0af65cffcf0825f1249deaaea7050f
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
#
# Empty/wrong machtype-workaround generator
#
@@ -20,8 +20,6 @@ check_lxdialog = $(shell $(SHELL) $(CURDIR)/lxdialog/check-lxdialog.sh -$(1))
export CFLAGS += -DKBUILD_NO_NLS -I. $(call check_lxdialog,ccflags)
export CXXFLAGS += -DKBUILD_NO_NLS

DISTRO-PKG-CONFIG := $(shell which -a pkg-config | grep -E '\/usr' | head -n 1)

conf-objs := conf.o zconf.tab.o
mconf-objs := mconf.o zconf.tab.o
qconf-cxxobjs := qconf.o
@@ -42,7 +40,7 @@ mconf: $(mconf-objs) $(lxdialog-objs)
$(CC) -o $@ $^ $(call check_lxdialog,ldflags $(CC))
qconf: $(qconf-cxxobjs) $(qconf-objs)
ifneq ($(DISTRO-PKG-CONFIG),)
$(CXX) $(HOSTLOADLIBES_qconf) -o $@ $^
$(CXX) -o $@ $^ $(HOSTLOADLIBES_qconf)
else
echo "You don't have 'pkg-config' installed. Cannot continue"
echo "For now, you may use 'make menuconfig' instead of 'make xconfig'"
@@ -177,7 +177,7 @@ def get(self, k):
def set(self, k, v):
"""Update timestamp with ``k``."""
fileno = os.open(self.cachef, os.O_RDWR | os.O_CREAT)
with os.fdopen(fileno, 'wb+') as f:
with os.fdopen(fileno, 'w+') as f:
try:
fcntl.lockf(fileno, fcntl.LOCK_EX)
self._cache_init(f)
@@ -203,7 +203,7 @@ def _cache_flush(self, fout):
ts = ent[0]
updated = ent[1]
line = '{0} {1} {2}\n'.format(k, ts, updated)
fout.write(line.encode('utf-8'))
fout.write(line)


class DownloadGitHubTarball(object):
@@ -73,7 +73,7 @@ env_init() {
}

env_sync_data() {
[ \! -L "$BASEDIR/.config" -a -f "$BASEDIR/.config" ] && mv "$BASEDIR/.config" "$ENVDIR"
[ \! -L "$BASEDIR/.config" ] && [ -f "$BASEDIR/.config" ] && mv "$BASEDIR/.config" "$ENVDIR"
git add .
git add -u
}
@@ -136,7 +136,7 @@ env_clear() {
env_init
[ -L "$BASEDIR/.config" ] && rm -f "$BASEDIR/.config"
[ -L "$BASEDIR/files" ] && rm -f "$BASEDIR/files"
[ -f "$ENVDIR/.config" ] || ( cd "$ENVDIR/files" && find | grep -vE '^\.$' > /dev/null )
[ -f "$ENVDIR/.config" ] || ( cd "$ENVDIR/files" && find . | grep -vE '^\.$' > /dev/null )
env_sync_data
if ask_bool 1 "Do you want to keep your current config and files"; then
mkdir -p "$BASEDIR/files"
@@ -185,23 +185,23 @@ env_new() {
env_init 1

branch="$(git branch | grep '^\* ' | awk '{print $2}')"
if [ -n "$branch" -a "$branch" != "master" ]; then
if [ -n "$branch" ] && [ "$branch" != "master" ]; then
env_ask_sync
if ask_bool 0 "Do you want to clone the current environment?"; then
from="$branch"
fi
rm -f "$BASEDIR/.config" "$BASEDIR/files"
fi
git checkout -b "$1" "$from"
if [ -f "$BASEDIR/.config" -o -d "$BASEDIR/files" ]; then
if [ -f "$BASEDIR/.config" ] || [ -d "$BASEDIR/files" ]; then
if ask_bool 1 "Do you want to start your configuration repository with the current configuration?"; then
[ -d "$BASEDIR/files" -a \! -L "$BASEDIR/files" ] && {
if [ -d "$BASEDIR/files" ] && [ \! -L "$BASEDIR/files" ]; then
mkdir -p "$ENVDIR/files"
shopt -s dotglob
mv "$BASEDIR/files/"* "$ENVDIR/files/" 2>/dev/null
shopt -u dotglob
rmdir "$BASEDIR/files"
}
fi
env_sync
else
rm -rf "$BASEDIR/.config" "$BASEDIR/files"
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
#
# Copyright (C) 2012 OpenWrt.org
#
@@ -24,8 +24,8 @@ find $TARGETS -type f -a -exec file {} \; | \
awk '$2 ~ /NEEDED/ && $NF !~ /interpreter/ && $NF ~ /^\[?lib.*\.so/ { gsub(/[\[\]]/, "", $NF); print $NF }' | \
sort -u

tmp=`mktemp $TMP_DIR/dep.XXXXXXXX`
for kmod in `find $TARGETS -type f -name \*.ko`; do
tmp=$(mktemp $TMP_DIR/dep.XXXXXXXX)
for kmod in $(find $TARGETS -type f -name \*.ko); do
$OBJCOPY -O binary -j .modinfo $kmod $tmp
sed -e 's,\x00,\n,g' $tmp | \
sed -ne '/^depends=.\+/ { s/^depends=//; s/,/.ko\n/g; s/$/.ko/p; q }'
@@ -17,10 +17,10 @@ rm -f "$OUTPUT"

head=16
sect=63
cyl=$(( ($KERNELSIZE + $ROOTFSSIZE) * 1024 * 1024 / ($head * $sect * 512)))
cyl=$(( (KERNELSIZE + ROOTFSSIZE) * 1024 * 1024 / (head * sect * 512)))

# create partition table
set `ptgen -o "$OUTPUT" -h $head -s $sect -p ${KERNELSIZE}m -p ${ROOTFSSIZE}m ${ALIGN:+-l $ALIGN} ${SIGNATURE:+-S 0x$SIGNATURE}`
set $(ptgen -o "$OUTPUT" -h $head -s $sect -p ${KERNELSIZE}m -p ${ROOTFSSIZE}m ${ALIGN:+-l $ALIGN} ${SIGNATURE:+-S 0x$SIGNATURE})

KERNELOFFSET="$(($1 / 512))"
KERNELSIZE="$2"
@@ -30,6 +30,6 @@ ROOTFSSIZE="$(($4 / 512))"
[ -n "$PADDING" ] && dd if=/dev/zero of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc count="$ROOTFSSIZE"
dd if="$ROOTFSIMAGE" of="$OUTPUT" bs=512 seek="$ROOTFSOFFSET" conv=notrunc

make_ext4fs -J -l "$KERNELSIZE" "$OUTPUT.kernel" "$KERNELDIR"
make_ext4fs -J -L kernel -l "$KERNELSIZE" "$OUTPUT.kernel" "$KERNELDIR"
dd if="$OUTPUT.kernel" of="$OUTPUT" bs=512 seek="$KERNELOFFSET" conv=notrunc
rm -f "$OUTPUT.kernel"
@@ -0,0 +1,55 @@
#!/usr/bin/env python3

import json
import os
import hashlib


def e(variable, default=None):
return os.environ.get(variable, default)


json_path = "{}{}{}.json".format(e("BIN_DIR"), os.sep, e("IMAGE_PREFIX"))

with open(os.path.join(e("BIN_DIR"), e("IMAGE_NAME")), "rb") as image_file:
image_hash = hashlib.sha256(image_file.read()).hexdigest()


def get_titles():
titles = []
for prefix in ["", "ALT0_", "ALT1_", "ALT2_"]:
title = {}
for var in ["vendor", "model", "variant"]:
if e("DEVICE_{}{}".format(prefix, var.upper())):
title[var] = e("DEVICE_{}{}".format(prefix, var.upper()))

if title:
titles.append(title)

if not titles:
titles.append({"title": e("DEVICE_TITLE")})

return titles


if not os.path.exists(json_path):
device_info = {
"id": e("DEVICE_ID"),
"image_prefix": e("IMAGE_PREFIX"),
"images": [],
"metadata_version": 1,
"supported_devices": e("SUPPORTED_DEVICES").split(),
"target": "{}/{}".format(e("TARGET"), e("SUBTARGET", "generic")),
"titles": get_titles(),
"version_commit": e("VERSION_CODE"),
"version_number": e("VERSION_NUMBER"),
}
else:
with open(json_path, "r") as json_file:
device_info = json.load(json_file)

image_info = {"type": e("IMAGE_TYPE"), "name": e("IMAGE_NAME"), "sha256": image_hash}
device_info["images"].append(image_info)

with open(json_path, "w") as json_file:
json.dump(device_info, json_file, sort_keys=True, indent=" ")
@@ -15,7 +15,7 @@
#

usage() {
echo "Usage: `basename $0` -A arch -C comp -a addr -e entry" \
echo "Usage: $(basename $0) -A arch -C comp -a addr -e entry" \
"-v version -k kernel [-D name -d dtb] -o its_file"
echo -e "\t-A ==> set architecture to 'arch'"
echo -e "\t-C ==> set compression type 'comp'"
@@ -55,7 +55,7 @@ if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
usage
fi

ARCH_UPPER=`echo $ARCH | tr '[:lower:]' '[:upper:]'`
ARCH_UPPER=$(echo $ARCH | tr '[:lower:]' '[:upper:]')

# Conditionally create fdt information
if [ -n "${DTB}" ]; then
@@ -0,0 +1,27 @@
#!/bin/sh

# directory where search for images
TOP_DIR="${TOP_DIR:-./bin/targets}"
# key to sign images
BUILD_KEY="${BUILD_KEY:-key-build}" # TODO unifiy naming?
# remove other signatures (added e.g. by buildbot)
REMOVE_OTER_SIGNATURES="${REMOVE_OTER_SIGNATURES:-1}"

# find all sysupgrade images in TOP_DIR
# factory images don't need signatures as non OpenWrt system doen't check them anyway
for image in $(find $TOP_DIR -type f -name "*-sysupgrade.bin"); do
# check if image actually support metadata
if fwtool -i /dev/null "$image"; then
# remove all previous signatures
if [ -n "$REMOVE_OTER_SIGNATURES" ]; then
while [ "$?" = 0 ]; do
fwtool -t -s /dev/null "$image"
done
fi
# run same operation as build root does for signing
cp "$BUILD_KEY.ucert" "$image.ucert"
usign -S -m "$image" -s "$BUILD_KEY" -x "$image.sig"
ucert -A -c "$image.ucert" -x "$image.sig"
fwtool -S "$image.ucert" "$image"
fi
done
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
[ -n "$CROSS" ] || {
echo "The variable CROSS must be set to point to the cross-compiler prefix"
exit 1
@@ -19,7 +19,7 @@ else
fi

if [ -z "$KEEP_BUILD_ID" ]; then
ARGS="$ARGS -R .note.gnu.build-id"
ARGS="$ARGS -R .note.gnu.build-id"
fi

${CROSS}objcopy \
@@ -50,6 +50,6 @@ $3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ && !def[$3] {
}
' > "$MODULE.tmp1"

${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
${CROSS}objcopy $(cat ${MODULE}.tmp1) ${MODULE}.tmp ${MODULE}.out
mv "${MODULE}.out" "${MODULE}"
rm -f "${MODULE}".t*
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/sh
# Create a new openwrt tree with symlinks pointing at the current tree
# Usage: ./scripts/symlink-tree.sh <destination>

@@ -9,6 +9,7 @@ kernel=""
rootfs=""
outfile=""
err=""
ubinize_seq=""

ubivol() {
volid=$1
@@ -81,6 +82,12 @@ ubilayout() {
[ "$rootfs_type" = "ubifs" ] || ubivol $vol_id rootfs_data "" 1
}

set_ubinize_seq() {
if [ -n "$SOURCE_DATE_EPOCH" ] ; then
ubinize_seq="-Q $SOURCE_DATE_EPOCH"
fi
}

while [ "$1" ]; do
case "$1" in
"--uboot-env")
@@ -137,8 +144,9 @@ if [ -z "$ubinizecfg" ]; then
fi
ubilayout "$ubootenv" "$rootfs" "$kernel" > "$ubinizecfg"

set_ubinize_seq
cat "$ubinizecfg"
ubinize -o "$outfile" $ubinize_param "$ubinizecfg"
ubinize $ubinize_seq -o "$outfile" $ubinize_param "$ubinizecfg"
err="$?"
[ ! -e "$outfile" ] && err=2
rm "$ubinizecfg"

0 comments on commit 90426b9

Please sign in to comment.
You can’t perform that action at this time.