Skip to content
Permalink
Browse files

trunk/scripts sync with owrt 2019.05

  • Loading branch information...
zyxmon committed May 21, 2019
1 parent f4e298f commit a05a0b3a9231a28c44539b37b7f621d9dba5be82
Showing with 88 additions and 18 deletions.
  1. +1 −0 scripts/clean-package.sh
  2. +1 −1 scripts/gen_image_generic.sh
  3. +5 −0 scripts/metadata.pm
  4. +64 −11 scripts/qemustart
  5. +17 −6 scripts/target-metadata.pl
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
IFS=$'\n'
[ -n "$1" -a -n "$2" ] || {
echo "Usage: $0 <file> <directory>"
exit 1
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Copyright (C) 2006-2012 OpenWrt.org
set -x
set -e -x
[ $# == 5 -o $# == 6 ] || {
echo "SYNTAX: $0 <file> <kernel size> <kernel directory> <rootfs size> <rootfs image> [<align>]"
exit 1
@@ -131,6 +131,7 @@ sub parse_target_metadata($) {
/^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1;
/^CPU-Type:\s*(.+)\s*$/ and $target->{cputype} = $1;
/^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
/^Linux-Testing-Version:\s*(.+)\s*$/ and $target->{testing_version} = $1;
/^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
/^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
/^Default-Subtarget:\s*(.+)\s*$/ and $target->{def_subtarget} = $1;
@@ -139,13 +140,17 @@ sub parse_target_metadata($) {
$profile = {
id => $1,
name => $1,
has_image_metadata => 0,
supported_devices => [],
priority => 999,
packages => []
};
$1 =~ /^DEVICE_/ and $target->{has_devices} = 1;
push @{$target->{profiles}}, $profile;
};
/^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
/^Target-Profile-hasImageMetadata:\s*(\d+)\s*$/ and $profile->{has_image_metadata} = $1;
/^Target-Profile-SupportedDevices:\s*(.+)\s*$/ and $profile->{supported_devices} = [ split(/\s+/, $1) ];
/^Target-Profile-Priority:\s*(\d+)\s*$/ and do {
$profile->{priority} = $1;
$target->{sort} = 1;
@@ -74,6 +74,7 @@ check_setup_() {
}

check_setup() {
[ -n "$o_network" ] || return 0
check_setup_ || {
__errmsg "please check the script content to see the environment requirement"
return 1
@@ -89,6 +90,7 @@ Usage: $SELF [-h|--help]
[--kernel <kernel>]
[--rootfs <rootfs>]
[--machine <machine>]
[-n|--network]
<subtarget> will default to "generic" and must be specified if
<extra-qemu-options> are present
@@ -119,12 +121,19 @@ rand_mac() {
}

parse_args() {
o_network=
o_qemu_extra=()
while [ "$#" -gt 0 ]; do
# Cmdline options for the script itself SHOULD try to be
# prefixed with two dashes to distinguish them from those for
# qemu executables.
#
# Also note that qemu accepts both --opt and -opt
case "$1" in
--kernel) o_kernel="$2"; shift 2 ;;
--rootfs) o_rootfs="$2"; shift 2 ;;
--machine|-machine|-M) o_mach="$2"; shift 2 ;;
--network|-n) o_network=1; shift ;;
--help|-h)
usage
exit 0
@@ -185,9 +194,16 @@ start_qemu_armvirt() {
)
}

[ -z "$o_network" ] || {
o_qemu_extra+=( \
"-netdev" "bridge,id=lan,br=$BR_LAN,helper=$HELPER" \
"-device" "virtio-net-pci,id=devlan,netdev=lan,mac=$MAC_LAN" \
"-netdev" "bridge,id=wan,br=$BR_WAN,helper=$HELPER" "-device" \
"virtio-net-pci,id=devwan,netdev=wan,mac=$MAC_WAN" \
)
}

"$qemu_exe" -machine "$mach" -cpu "$cpu" -nographic \
-netdev bridge,id=lan,br="$BR_LAN,helper=$HELPER" -device virtio-net-pci,id=devlan,netdev=lan,mac="$MAC_LAN" \
-netdev bridge,id=wan,br="$BR_WAN,helper=$HELPER" -device virtio-net-pci,id=devwan,netdev=wan,mac="$MAC_WAN" \
-kernel "$kernel" \
"${o_qemu_extra[@]}"
}
@@ -196,6 +212,7 @@ start_qemu_malta() {
local is64
local isel
local qemu_exe
local rootfs="$o_rootfs"
local kernel="$o_kernel"
local mach="${o_mach:-malta}"

@@ -206,20 +223,36 @@ start_qemu_malta() {

[ -n "$kernel" ] || kernel="$o_bindir/openwrt-malta-${o_subtarget%-*}-vmlinux-initramfs.elf"

[ -z "$rootfs" ] || {
if [ ! -f "$rootfs" -a -s "$rootfs.gz" ]; then
gunzip "$rootfs.gz"
fi
o_qemu_extra+=( \
"-drive" "file=$rootfs,format=raw" \
"-append" "root=/dev/sda rootwait" \
)
}

# NOTE: order of wan, lan -device arguments matters as it will affect which
# one will be actually used as the wan, lan network interface inside the
# guest machine
[ -z "$o_network" ] || {
o_qemu_extra+=(
-netdev bridge,id=wan,br="$BR_WAN,helper=$HELPER" -device pcnet,netdev=wan,mac="$MAC_WAN"
-netdev bridge,id=lan,br="$BR_LAN,helper=$HELPER" -device pcnet,netdev=lan,mac="$MAC_LAN"
)
}

"$qemu_exe" -machine "$mach" -nographic \
-netdev bridge,id=wan,br="$BR_WAN,helper=$HELPER" -device pcnet,netdev=wan,mac="$MAC_WAN" \
-netdev bridge,id=lan,br="$BR_LAN,helper=$HELPER" -device pcnet,netdev=lan,mac="$MAC_LAN" \
-kernel "$kernel" \
"${o_qemu_extra[@]}"
}

start_qemu_x86() {
local qemu_exe
local kernel="$o_kernel"
local rootfs="$o_rootfs"
local mach="${o_mach:-pc}"
local qemu_exe

[ -n "$rootfs" ] || {
rootfs="$o_bindir/openwrt-$o_target-${o_subtarget%-*}-combined-ext4.img"
@@ -241,6 +274,30 @@ start_qemu_x86() {
;;
esac

[ -n "$kernel" ] && {
o_qemu_extra+=( \
"-kernel" "$kernel" \
"-append" "root=/dev/vda console=ttyS0 rootwait" \
)
}

[ -z "$o_network" ] || {
case "${o_subtarget%-*}" in
legacy)
o_qemu_extra+=(
-netdev "bridge,id=lan,br=$BR_LAN,helper=$HELPER" -device "e1000,id=devlan,netdev=lan,mac=$MAC_LAN"
-netdev "bridge,id=wan,br=$BR_WAN,helper=$HELPER" -device "e1000,id=devwan,netdev=wan,mac=$MAC_WAN"
)
;;
generic|64)
o_qemu_extra+=(
-netdev "bridge,id=lan,br=$BR_LAN,helper=$HELPER" -device "virtio-net-pci,id=devlan,netdev=lan,mac=$MAC_LAN"
-netdev "bridge,id=wan,br=$BR_WAN,helper=$HELPER" -device "virtio-net-pci,id=devwan,netdev=wan,mac=$MAC_WAN"
)
;;
esac
}

case "${o_subtarget%-*}" in
legacy)
# use IDE (PATA) disk instead of AHCI (SATA). Refer to link
@@ -254,16 +311,12 @@ start_qemu_x86() {
#
# [1] https://dev.openwrt.org/ticket/17947
"$qemu_exe" -machine "$mach" -nographic \
-netdev bridge,id=lan,br="$BR_LAN,helper=$HELPER" -device e1000,id=devlan,netdev=lan,mac="$MAC_LAN" \
-netdev bridge,id=wan,br="$BR_WAN,helper=$HELPER" -device e1000,id=devwan,netdev=wan,mac="$MAC_WAN" \
-device ide-drive,drive=drv0 \
-drive "file=$rootfs,format=raw,id=drv0,if=none" \
"${o_qemu_extra[@]}"
;;
generic|64)
"$qemu_exe" -machine "$mach" -nographic \
-netdev bridge,id=lan,br="$BR_LAN,helper=$HELPER" -device virtio-net-pci,id=devlan,netdev=lan,mac="$MAC_LAN" \
-netdev bridge,id=wan,br="$BR_WAN,helper=$HELPER" -device virtio-net-pci,id=devwan,netdev=wan,mac="$MAC_WAN" \
-drive "file=$rootfs,format=raw,if=virtio" \
"${o_qemu_extra[@]}"
;;
@@ -282,6 +335,6 @@ start_qemu() {
esac
}

check_setup \
&& parse_args "$@" \
parse_args "$@" \
&& check_setup \
&& start_qemu
@@ -42,6 +42,7 @@ (@)
/^virtio$/ and $ret .= "\tselect VIRTIO_SUPPORT\n";
/^rootfs-part$/ and $ret .= "\tselect USES_ROOTFS_PART\n";
/^boot-part$/ and $ret .= "\tselect USES_BOOT_PART\n";
/^testing-kernel$/ and $ret .= "\tselect HAS_TESTING_KERNEL\n";
}
return $ret;
}
@@ -83,11 +84,14 @@ ($)
}

my $v = kver($target->{version});
my $tv = kver($target->{testing_version});
$tv or $tv = $v;
if (@{$target->{subtargets}} == 0) {
$confstr = <<EOF;
config TARGET_$target->{conf}
bool "$target->{name}"
select LINUX_$v
select LINUX_$v if !TESTING_KERNEL
select LINUX_$tv if TESTING_KERNEL
EOF
}
else {
@@ -170,7 +174,7 @@ ()
print <<EOF;
choice
prompt "Target System"
default TARGET_ar71xx
default TARGET_ath79
reset if !DEVEL
EOF
@@ -387,15 +391,18 @@ ()

my %kver;
foreach my $target (@target) {
my $v = kver($target->{version});
next if $kver{$v};
$kver{$v} = 1;
print <<EOF;
foreach my $tv ($target->{version}, $target->{testing_version}) {
next unless $tv;
my $v = kver($tv);
next if $kver{$v};
$kver{$v} = 1;
print <<EOF;
config LINUX_$v
bool
EOF
}
}
foreach my $def (sort keys %defaults) {
print <<EOF;
@@ -422,6 +429,10 @@ ()
print "PROFILE_NAMES = ".join(" ", map { $_->{id} } @{$cur->{profiles}})."\n";
foreach my $profile (@{$cur->{profiles}}) {
print $profile->{id}.'_NAME:='.$profile->{name}."\n";
print $profile->{id}.'_HAS_IMAGE_METADATA:='.$profile->{has_image_metadata}."\n";
if (defined($profile->{supported_devices}) and @{$profile->{supported_devices}} > 0) {
print $profile->{id}.'_SUPPORTED_DEVICES:='.join(' ', @{$profile->{supported_devices}})."\n";
}
print $profile->{id}.'_PACKAGES:='.join(' ', @{$profile->{packages}})."\n";
}
}

0 comments on commit a05a0b3

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