解决 编译内核出现kernel/timeconst.pl line 373问题

解决Ubuntu内核编译错误
本文介绍在Ubuntu16.4环境下编译Linux-3.0.8内核时遇到的一个特定错误,并提供了解决方案。错误发生在timeconst.pl脚本中,涉及defined()函数的使用。通过简单修改脚本内容即可成功完成内核编译。

在使用ubuntu16.4编译linux-3.0.8内核时出现这样的错误

在之前的版本编译时是可以正常编译通过,还不清楚具体问题

但是可以修改timeconst.pl的内容后正常编译。

以下是编译错误提示的内容:

Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373.
/opt/ARM/mini6410/linux/linux-2.6.38/kernel/Makefile:140: recipe for target 'kernel/timeconst.h' failed
make[1]: *** [kernel/timeconst.h] Error 255
Makefile:916: recipe for target 'kernel' failed
make: *** [kernel] Error 2

将kernel/timeconst.pl中第373行的defined()去掉只留下@val就可以了

#!/usr/bin/env perl # # Copyright (C) 2006 OpenWrt.org # Copyright (C) 2016 LEDE project # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # use strict; use warnings; use File::Basename; use File::Copy; use Text::ParseWords; @ARGV > 2 or die "Syntax: $0 <target dir> <filename> <hash> <url filename> [<mirror> ...]\n"; my $url_filename; my $target = glob(shift @ARGV); my $filename = shift @ARGV; my $file_hash = shift @ARGV; $url_filename = shift @ARGV unless $ARGV[0] =~ /:\/\//; my $scriptdir = dirname($0); my @mirrors; my $ok; my $check_certificate = $ENV{DOWNLOAD_CHECK_CERTIFICATE} eq "y"; $url_filename or $url_filename = $filename; sub localmirrors { my @mlist; open LM, "$scriptdir/localmirrors" and do { while (<LM>) { chomp $_; push @mlist, $_ if $_; } close LM; }; open CONFIG, "<".$ENV{'TOPDIR'}."/.config" and do { while (<CONFIG>) { /^CONFIG_LOCALMIRROR="(.+)"/ and do { chomp; my @local_mirrors = split(/;/, $1); push @mlist, @local_mirrors; }; } close CONFIG; }; my $mirror = $ENV{'DOWNLOAD_MIRROR'}; $mirror and push @mlist, split(/;/, $mirror); return @mlist; } sub which($) { my $prog = shift; my $res = `command -v $prog`; $res or return undef; return $res; } sub hash_cmd() { my $len = length($file_hash); my $cmd; $len == 64 and return "$ENV{'MKHASH'} sha256"; $len == 32 and return "$ENV{'MKHASH'} md5"; return undef; } sub download_cmd($) { my $url = shift; my $have_curl = 0; if (open CURL, "curl --version 2>/dev/null |") { if (defined(my $line = readline CURL)) { $have_curl = 1 if $line =~ /^curl /; } close CURL; } return $have_curl ? (qw(curl -k -f --connect-timeout 20 --retry 5 --location), $check_certificate ? () : '--insecure', shellwords($ENV{CURL_OPTIONS} || ''), $url) : (qw(wget --tries=5 --timeout=20 --output-document=-), $check_certificate ? () : '--no-check-certificate', shellwords($ENV{WGET_OPTIONS} || ''), $url) ; } my $hash_cmd = hash_cmd(); $hash_cmd or ($file_hash eq "skip") or die "Cannot find appropriate hash command, ensure the provided hash is either a MD5 or SHA256 checksum.\n"; sub download { my $mirror = shift; my $download_filename = shift; $mirror =~ s!/$!!; if ($mirror =~ s!^file://!!) { if (! -d "$mirror") { print STDERR "Wrong local cache directory -$mirror-.\n"; cleanup(); return; } if (! -d "$target") { system("mkdir", "-p", "$target/"); } if (! open TMPDLS, "find $mirror -follow -name $filename 2>/dev/null |") { print("Failed to search for $filename in $mirror\n"); return; } my $link; while (defined(my $line = readline TMPDLS)) { chomp ($link = $line); if ($. > 1) { print("$. or more instances of $filename in $mirror found . Only one instance allowed.\n"); return; } } close TMPDLS; if (! $link) { print("No instances of $filename found in $mirror.\n"); return; } print("Copying $filename from $link\n"); copy($link, "$target/$filename.dl"); $hash_cmd and do { if (system("cat '$target/$filename.dl' | $hash_cmd > '$target/$filename.hash'")) { print("Failed to generate hash for $filename\n"); return; } }; } else { my @cmd = download_cmd("$mirror/$download_filename"); print STDERR "+ ".join(" ",@cmd)."\n"; open(FETCH_FD, '-|', @cmd) or die "Cannot launch curl or wget.\n"; $hash_cmd and do { open MD5SUM, "| $hash_cmd > '$target/$filename.hash'" or die "Cannot launch $hash_cmd.\n"; }; open OUTPUT, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n"; my $buffer; while (read FETCH_FD, $buffer, 1048576) { $hash_cmd and print MD5SUM $buffer; print OUTPUT $buffer; } $hash_cmd and close MD5SUM; close FETCH_FD; close OUTPUT; if ($? >> 8) { print STDERR "Download failed.\n"; cleanup(); return; } } $hash_cmd and do { my $sum = `cat "$target/$filename.hash"`; $sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n"; $sum = $1; if ($sum ne $file_hash) { print STDERR "Hash of the downloaded file does not match (file: $sum, requested: $file_hash) - deleting download.\n"; cleanup(); return; } }; unlink "$target/$filename"; system("mv", "$target/$filename.dl", "$target/$filename"); cleanup(); } sub cleanup { unlink "$target/$filename.dl"; unlink "$target/$filename.hash"; } @mirrors = localmirrors(); foreach my $mirror (@ARGV) { if ($mirror =~ /^\@SF\/(.+)$/) { # give sourceforge a few more tries, because it redirects to different mirrors for (1 .. 5) { push @mirrors, "https://downloads.sourceforge.net/$1"; } } elsif ($mirror =~ /^\@OPENWRT$/) { # use OpenWrt source server directly } elsif ($mirror =~ /^\@DEBIAN\/(.+)$/) { push @mirrors, "https://ftp.debian.org/debian/$1"; push @mirrors, "https://mirror.leaseweb.com/debian/$1"; push @mirrors, "https://mirror.netcologne.de/debian/$1"; } elsif ($mirror =~ /^\@APACHE\/(.+)$/) { push @mirrors, "https://mirror.netcologne.de/apache.org/$1"; push @mirrors, "https://mirror.aarnet.edu.au/pub/apache/$1"; push @mirrors, "https://mirror.csclub.uwaterloo.ca/apache/$1"; push @mirrors, "https://archive.apache.org/dist/$1"; push @mirrors, "http://mirror.cogentco.com/pub/apache/$1"; push @mirrors, "http://mirror.navercorp.com/apache/$1"; push @mirrors, "http://ftp.jaist.ac.jp/pub/apache/$1"; push @mirrors, "ftp://apache.cs.utah.edu/apache.org/$1"; push @mirrors, "ftp://apache.mirrors.ovh.net/ftp.apache.org/dist/$1"; } elsif ($mirror =~ /^\@GITHUB\/(.+)$/) { # give github a few more tries (different mirrors) for (1 .. 5) { push @mirrors, "https://raw.githubusercontent.com/$1"; } } elsif ($mirror =~ /^\@GNU\/(.+)$/) { push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnu/$1"; push @mirrors, "https://mirror.netcologne.de/gnu/$1"; push @mirrors, "http://ftp.kddilabs.jp/GNU/gnu/$1"; push @mirrors, "http://www.nic.funet.fi/pub/gnu/gnu/$1"; push @mirrors, "http://mirror.internode.on.net/pub/gnu/$1"; push @mirrors, "http://mirror.navercorp.com/gnu/$1"; push @mirrors, "ftp://mirrors.rit.edu/gnu/$1"; push @mirrors, "ftp://download.xs4all.nl/pub/gnu/$1"; push @mirrors, "https://ftp.gnu.org/gnu/$1"; } elsif ($mirror =~ /^\@SAVANNAH\/(.+)$/) { push @mirrors, "https://mirror.netcologne.de/savannah/$1"; push @mirrors, "https://mirror.csclub.uwaterloo.ca/nongnu/$1"; push @mirrors, "http://ftp.acc.umu.se/mirror/gnu.org/savannah/$1"; push @mirrors, "http://nongnu.uib.no/$1"; push @mirrors, "http://ftp.igh.cnrs.fr/pub/nongnu/$1"; push @mirrors, "ftp://cdimage.debian.org/mirror/gnu.org/savannah/$1"; push @mirrors, "ftp://ftp.acc.umu.se/mirror/gnu.org/savannah/$1"; } elsif ($mirror =~ /^\@KERNEL\/(.+)$/) { my @extra = ( $1 ); if ($filename =~ /linux-\d+\.\d+(?:\.\d+)?-rc/) { push @extra, "$extra[0]/testing"; } elsif ($filename =~ /linux-(\d+\.\d+(?:\.\d+)?)/) { push @extra, "$extra[0]/longterm/v$1"; } foreach my $dir (@extra) { push @mirrors, "https://cdn.kernel.org/pub/$dir"; push @mirrors, "https://download.xs4all.nl/ftp.kernel.org/pub/$dir"; push @mirrors, "https://mirrors.mit.edu/kernel/$dir"; push @mirrors, "http://ftp.nara.wide.ad.jp/pub/kernel.org/$dir"; push @mirrors, "http://www.ring.gr.jp/archives/linux/kernel.org/$dir"; push @mirrors, "ftp://ftp.riken.jp/Linux/kernel.org/$dir"; push @mirrors, "ftp://www.mirrorservice.org/sites/ftp.kernel.org/pub/$dir"; } } elsif ($mirror =~ /^\@GNOME\/(.+)$/) { push @mirrors, "https://download.gnome.org/sources/$1"; push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnome/sources/$1"; push @mirrors, "http://ftp.acc.umu.se/pub/GNOME/sources/$1"; push @mirrors, "http://ftp.kaist.ac.kr/gnome/sources/$1"; push @mirrors, "http://www.mirrorservice.org/sites/ftp.gnome.org/pub/GNOME/sources/$1"; push @mirrors, "http://mirror.internode.on.net/pub/gnome/sources/$1"; push @mirrors, "http://ftp.belnet.be/ftp.gnome.org/sources/$1"; push @mirrors, "ftp://ftp.cse.buffalo.edu/pub/Gnome/sources/$1"; push @mirrors, "ftp://ftp.nara.wide.ad.jp/pub/X11/GNOME/sources/$1"; } else { push @mirrors, $mirror; } } push @mirrors, 'https://sources.cdn.openwrt.org'; push @mirrors, 'https://sources.openwrt.org'; push @mirrors, 'https://mirror2.openwrt.org/sources'; if (-f "$target/$filename") { $hash_cmd and do { if (system("cat '$target/$filename' | $hash_cmd > '$target/$filename.hash'")) { die "Failed to generate hash for $filename\n"; } my $sum = `cat "$target/$filename.hash"`; $sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n"; $sum = $1; cleanup(); exit 0 if $sum eq $file_hash; die "Hash of the local file $filename does not match (file: $sum, requested: $file_hash) - deleting download.\n"; unlink "$target/$filename"; }; } while (!-f "$target/$filename") { my $mirror = shift @mirrors; $mirror or die "No more mirrors to try - giving up.\n"; download($mirror, $url_filename); if (!-f "$target/$filename" && $url_filename ne $filename) { download($mirror, $filename); } } $SIG{INT} = \&cleanup; 针对意思代码,解释:我是内网办公,所以不能从远端获取下载包,即dl中的下载包只能是编译前就准备好的,但是现在我断网后每次下载都失败,为什么?
07-16
请告诉我具体的实验步骤: Lab: system calls In the last lab you used system calls to write a few utilities. In this lab you will add some new system calls to xv6, which will help you understand how they work and will expose you to some of the internals of the xv6 kernel. You will add more system calls in later labs. Before you start coding, read Chapter 2 of the xv6 book, and Sections 4.3 and 4.4 of Chapter 4, and related source files: • The user-space "stubs" that route system calls into the kernel are in user/usys.S, which is generated by user/usys.pl when you run make. Declarations are in user/user.h • The kernel-space code that routes a system call to the kernel function that implements it is in kernel/syscall.c and kernel/syscall.h. • Process-related code is kernel/proc.h and kernel/proc.c. To start the lab, switch to the syscall branch: $ git fetch $ git checkout syscall $ make clean If you run make grade you will see that the grading script cannot exec trace and sysinfotest. Your job is to add the necessary system calls and stubs to make them work. Using gdb (easy) In many cases, print statements will be sufficient to debug your kernel, but sometimes being able to single step through some assembly code or inspecting the variables on the stack is helpful. To learn more about how to run GDB and the common issues that can arise when using GDB, check out this page. To help you become familiar with gdb, run and then fire up gdb in another window (see the gdb bullet on the guidance page). Once you have two windows open, type in the gdb window: make qemu-gdb (gdb) b syscall Breakpoint 1 at 0x80002142: file kernel/syscall.c, line 243. (gdb) c Continuing. [Switching to Thread 1.2] Thread 2 hit Breakpoint 1, syscall () at kernel/syscall.c:243 243 { (gdb) layout src (gdb) backtrace The layout command splits the window in two, showing where gdb is in the source code. The backtrace prints out the stack backtrace. See Using the GNU Debugger for helpful GDB commands. Answer the following questions in answers-syscall.txt. Looking at the backtrace output, which function called syscall? Type a few times to step past struct proc *p = myproc(); Once past this statement, type , which prints the current process's proc struct (see kernel/proc.h>) in hex. np /x *p What is the value of p->trapframe->a7 and what does that value represent? (Hint: look user/initcode.S, the first user program xv6 starts.) The processor is running in kernel mode, and we can print privileged registers such as sstatus (see RISC-V privileged instructions for a description): (gdb) p /x $sstatus What was the previous mode that the CPU was in? In the subsequent part of this lab (or in following labs), it may happen that you make a programming error that causes the xv6 kernel to panic. For example, replace the statement num = p->trapframe->a7; with num = * (int *) 0; at the beginning of syscall, run , and you will see something similar to: make qemu xv6 kernel is booting hart 2 starting hart 1 starting scause 0x000000000000000d sepc=0x000000008000215a stval=0x0000000000000000 panic: kerneltrap Quit out of qemu. To track down the source of a kernel page-fault panic, search for the sepc value printed for the panic you just saw in the file kernel/kernel.asm, which contains the assembly for the compiled kernel. Write down the assembly instruction the kernel is panicing at. Which register corresponds to the variable num? To inspect the state of the processor and the kernel at the faulting instruction, fire up gdb, and set a breakpoint at the faulting epc, like this: (gdb) b *0x000000008000215a Breakpoint 1 at 0x8000215a: file kernel/syscall.c, line 247. (gdb) layout asm (gdb) c Continuing. [Switching to Thread 1.3] Thread 3 hit Breakpoint 1, syscall () at kernel/syscall.c:247 Confirm that the faulting assembly instruction is the same as the one you found above. Why does the kernel crash? Hint: look at figure 3-3 in the text; is address 0 mapped in the kernel address space? Is that confirmed by the value in scause above? (See description of scause in RISC-V privileged instructions) Note that scause was printed by the kernel panic above, but often you need to look at additional info to track down the problem that caused the panic. For example, to find out which user process was running when the kernel paniced, you can print out the process's name: (gdb) p p->name What is the name of the binary that was running when the kernel paniced? What is its process id (pid)? This concludes a brief introduction to tracking down bugs with gdb; it is worth your time to revisit Using the GNU Debugger when tracking down kernel bugs. The guidance page also has some other other useful debugging tips.
最新发布
11-16
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值