OpenWrt之获取target architectures列表

@

OpenWrt之获取target architectures列表


前言

最近在了解OpenWrt中看到了个有趣的perl脚本, 可以打印出整个target信息以及架构内核, 也是他们的download页的大概框架


分析脚本

scripts/dump-target-info.pl

#!/usr/bin/env perl

use strict;
use warnings;
use Cwd;

my (%targets, %architectures, %kernels);

$ENV{'TOPDIR'} = Cwd::getcwd();


sub parse_targetinfo {
	my ($target_dir, $subtarget) = @_;

	if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 SUBTARGET='$subtarget' |") {
		my ($target_name, $target_arch, $target_kernel, $target_testing_kernel, @target_features);
		while (defined(my $line = readline M)) {
			chomp $line;

			if ($line =~ /^Target: (.+)$/) {
				$target_name = $1;
			}
			elsif ($line =~ /^Target-Arch-Packages: (.+)$/) {
				$target_arch = $1;
			}
			elsif ($line =~ /^Linux-Version: (\d\.\d+)\.\d+$/) {
				$target_kernel = $1;
			}
			elsif ($line =~ /^Linux-Testing-Version: (\d\.\d+)\.\d+$/) {
				$target_testing_kernel = $1;
			}
			elsif ($line =~ /^Target-Features: (.+)$/) {
				@target_features = split /\s+/, $1;
			}
			elsif ($line =~ /^@\@$/) {
				if ($target_name && $target_arch && $target_kernel &&
				    !grep { $_ eq 'broken' or $_ eq 'source-only' } @target_features) {
					$targets{$target_name} = $target_arch;
					$architectures{$target_arch} ||= [];
					push @{$architectures{$target_arch}}, $target_name;
					$kernels{$target_name} ||= [];
					push @{$kernels{$target_name}}, $target_kernel;
					if ($target_testing_kernel) {
						push @{$kernels{$target_name}}, $target_testing_kernel;
					}
				}

				undef $target_name;
				undef $target_arch;
				undef $target_kernel;
				undef $target_testing_kernel;
				@target_features = ();
			}
		}
		close M;
	}
}

sub get_targetinfo {
	foreach my $target_makefile (glob "target/linux/*/Makefile") {
		my ($target_dir) = $target_makefile =~ m!^(.+)/Makefile$!;
		my @subtargets;

		if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.FEATURES V=s 2>/dev/null |") {
			if (defined(my $line = readline M)) {
				chomp $line;
				if (grep { $_ eq 'broken' or $_ eq 'source-only' } split /\s+/, $line) {
					next;
				}
			}
		}

		if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.SUBTARGETS V=s 2>/dev/null |") {
			if (defined(my $line = readline M)) {
				chomp $line;
				@subtargets = split /\s+/, $line;
			}
			close M;
		}

		push @subtargets, 'generic' if @subtargets == 0;

		foreach my $subtarget (@subtargets) {
			parse_targetinfo($target_dir, $subtarget);
		}
	}
}

if (@ARGV == 1 && $ARGV[0] eq 'targets') {
	get_targetinfo();
	foreach my $target_name (sort keys %targets) {
		printf "%s %s\n", $target_name, $targets{$target_name};
	}
}
elsif (@ARGV == 1 && $ARGV[0] eq 'architectures') {
	get_targetinfo();
	foreach my $target_arch (sort keys %architectures) {
		printf "%s %s\n", $target_arch, join ' ', @{$architectures{$target_arch}};
	}
}
elsif (@ARGV == 1 && $ARGV[0] eq 'kernels') {
	get_targetinfo();
	foreach my $target_name (sort keys %targets) {
		printf "%s %s\n", $target_name, join ' ', @{$kernels{$target_name}};
	}
}
else {
	print "Usage: $0 targets\n";
	print "Usage: $0 architectures\n";
	print "Usage: $0 kernels\n";
}
  • 用法
  • scripts/dump-target-info.pl 参数
  • 一共三个参数可选, 分别是targets, architectures, kernels

targets参数

  • 命令
perl ./scripts/dump-target-info.pl targets 2>/dev/null
  • 返回信息
apm821xx/nand powerpc_464fp
apm821xx/sata powerpc_464fp
archs38/generic arc_archs
armvirt/32 arm_cortex-a15_neon-vfpv4
armvirt/64 aarch64_cortex-a53
at91/sam9x arm_arm926ej-s
at91/sama5 arm_cortex-a5_vfpv4
at91/sama7 arm_cortex-a7_vfpv4
ath25/generic mips_mips32
ath79/generic mips_24kc
ath79/mikrotik mips_24kc
ath79/nand mips_24kc
ath79/tiny mips_24kc
bcm27xx/bcm2708 arm_arm1176jzf-s_vfp
bcm27xx/bcm2709 arm_cortex-a7_neon-vfpv4
bcm27xx/bcm2710 aarch64_cortex-a53
bcm27xx/bcm2711 aarch64_cortex-a72
bcm47xx/generic mipsel_mips32
bcm47xx/legacy mipsel_mips32
bcm47xx/mips74k mipsel_74kc
bcm4908/generic aarch64_cortex-a53
bcm53xx/generic arm_cortex-a9
bcm63xx/generic mips_mips32
bcm63xx/smp mips_mips32
gemini/generic arm_fa526
imx/cortexa7 arm_cortex-a7_neon-vfpv4
imx/cortexa9 arm_cortex-a9_neon
ipq40xx/chromium arm_cortex-a7_neon-vfpv4
ipq40xx/generic arm_cortex-a7_neon-vfpv4
ipq40xx/mikrotik arm_cortex-a7_neon-vfpv4
ipq806x/generic arm_cortex-a15_neon-vfpv4
kirkwood/generic arm_xscale
lantiq/ase mips_mips32
lantiq/xrx200 mips_24kc
lantiq/xway mips_24kc
lantiq/xway_legacy mips_24kc
layerscape/armv7 arm_cortex-a7_neon-vfpv4
layerscape/armv8_64b aarch64_generic
malta/be mips_24kc
mediatek/mt7622 aarch64_cortex-a53
mediatek/mt7623 arm_cortex-a7_neon-vfpv4
mediatek/mt7629 arm_cortex-a7
mpc85xx/p1010 powerpc_8540
mpc85xx/p1020 powerpc_8540
mpc85xx/p2020 powerpc_8540
mvebu/cortexa53 aarch64_cortex-a53
mvebu/cortexa72 aarch64_cortex-a72
mvebu/cortexa9 arm_cortex-a9_vfpv3-d16
mxs/generic arm_arm926ej-s
octeon/generic mips64_octeonplus
octeontx/generic aarch64_generic
omap/generic arm_cortex-a8_vfpv3
oxnas/ox820 arm_mpcore
pistachio/generic mipsel_24kc_24kf
ramips/mt7620 mipsel_24kc
ramips/mt7621 mipsel_24kc
ramips/mt76x8 mipsel_24kc
ramips/rt288x mipsel_24kc
ramips/rt305x mipsel_24kc
ramips/rt3883 mipsel_74kc
realtek/rtl838x mips_4kec
realtek/rtl839x mips_24kc
realtek/rtl930x mips_24kc
realtek/rtl931x mips_24kc
rockchip/armv8 aarch64_generic
sunxi/cortexa53 aarch64_cortex-a53
sunxi/cortexa7 arm_cortex-a7_neon-vfpv4
sunxi/cortexa8 arm_cortex-a8_vfpv3
tegra/generic arm_cortex-a9_vfpv3-d16
x86/64 x86_64
x86/generic i386_pentium4
x86/geode i386_pentium-mmx
x86/legacy i386_pentium-mmx
zynq/generic arm_cortex-a9_neon
  • 解析

左边是cpu, 右边是cpu的架构


architectures参数

  • 命令
perl ./scripts/dump-target-info.pl architectures 2>/dev/null
  • 返回信息
aarch64_cortex-a53 armvirt/64 bcm27xx/bcm2710 bcm4908/generic mediatek/mt7622 mvebu/cortexa53 sunxi/cortexa53
aarch64_cortex-a72 bcm27xx/bcm2711 mvebu/cortexa72
aarch64_generic layerscape/armv8_64b octeontx/generic rockchip/armv8
arc_archs archs38/generic
arm_arm1176jzf-s_vfp bcm27xx/bcm2708
arm_arm926ej-s at91/sam9x mxs/generic
arm_cortex-a15_neon-vfpv4 armvirt/32 ipq806x/generic
arm_cortex-a5_vfpv4 at91/sama5
arm_cortex-a7 mediatek/mt7629
arm_cortex-a7_neon-vfpv4 bcm27xx/bcm2709 imx/cortexa7 ipq40xx/generic ipq40xx/chromium ipq40xx/mikrotik layerscape/armv7 mediatek/mt7623 sunxi/cortexa7
arm_cortex-a7_vfpv4 at91/sama7
arm_cortex-a8_vfpv3 omap/generic sunxi/cortexa8
arm_cortex-a9 bcm53xx/generic
arm_cortex-a9_neon imx/cortexa9 zynq/generic
arm_cortex-a9_vfpv3-d16 mvebu/cortexa9 tegra/generic
arm_fa526 gemini/generic
arm_mpcore oxnas/ox820
arm_xscale kirkwood/generic
i386_pentium-mmx x86/legacy x86/geode
i386_pentium4 x86/generic
mips64_octeonplus octeon/generic
mips_24kc ath79/generic ath79/mikrotik ath79/nand ath79/tiny lantiq/xrx200 lantiq/xway lantiq/xway_legacy malta/be realtek/rtl839x realtek/rtl930x realtek/rtl931x
mips_4kec realtek/rtl838x
mips_mips32 ath25/generic bcm63xx/generic bcm63xx/smp lantiq/ase
mipsel_24kc ramips/mt7620 ramips/mt7621 ramips/mt76x8 ramips/rt288x ramips/rt305x
mipsel_24kc_24kf pistachio/generic
mipsel_74kc bcm47xx/mips74k ramips/rt3883
mipsel_mips32 bcm47xx/generic bcm47xx/legacy
powerpc_464fp apm821xx/nand apm821xx/sata
powerpc_8540 mpc85xx/p1010 mpc85xx/p1020 mpc85xx/p2020
x86_64 x86/64
  • 解析

左边是架构, 右边是此架构的cpu


kernels参数

  • 命令
perl ./scripts/dump-target-info.pl kernels 2>/dev/null
  • 返回信息
# 省略N行
apm821xx/nand 5.10
apm821xx/sata 5.10
arc770/generic 5.4
archs38/generic 5.4
armvirt/32 5.10
armvirt/64 5.10
at91/sam9x 5.10
at91/sama5 5.10
ath25/generic 5.4
ath79/generic 5.4 5.10
ath79/mikrotik 5.4 5.10
# 省略N行
  • 解析

左边是cpu, 中间是kernel verison, 右边是testing kernel version


欢迎关注公众号: [NueXiniShare], Enjoy it ~

posted @ 2022-08-02 18:09  虐心i  阅读(650)  评论(0编辑  收藏  举报