blob: e025bf5d33e5c3d879093e85e04b05bb1393c09f [file] [log] [blame]
Pi-Hsun Shihd3121bb2020-07-09 07:41:121#!/bin/bash
Mike Frysinger8b0fc372022-09-08 07:24:242# Copyright 2020 The ChromiumOS Authors
Pi-Hsun Shihd3121bb2020-07-09 07:41:123# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# Loads script libraries.
7CONTRIB_DIR=$(dirname "$(readlink -f "$0")")
8. "${CONTRIB_DIR}/common.sh" || exit 1
9
10FLAGS_HELP="
11Decode kernel stack trace from kernel logs.
12
13Read kernel logs from stdin, and print the decoded stack trace to stdout.
14
15Usage:
16 kernel_decode_stack -b <board>
17"
18
19# Flags
20DEFINE_string board "${DEFAULT_BOARD}" "Which board to decode stack trace" b
21
22# Parse command line.
23FLAGS "$@" || exit 1
24eval set -- "${FLAGS_ARGV}"
25set -e
26
27# Script must be run inside the chroot.
28assert_inside_chroot
29
30decode_stacktrace() {
31 local board="$1"
32 shift
33
34 local CHOST
35 CHOST=$("portageq-${board}" envvar CHOST)
36
37 local ARCH
38 ARCH=$("portageq-${board}" envvar ARCH)
39
Maksim Ivanov44a91d42023-08-29 10:14:2540 # cros-kernel.eclass falls back to tc-arch-kernel when CHROMEOS_KERNEL_ARCH
Pi-Hsun Shihd3121bb2020-07-09 07:41:1241 # is not set, but since tc-arch-kernel parse the arch from CHOST, we can just
42 # ignnore kernel_arch and use the original CHOST as CROSS_COMPILE in this
43 # case.
44 local kernel_arch
45 kernel_arch=$("portageq-${board}" envvar CHROMEOS_KERNEL_ARCH || true)
46
Maksim Ivanov44a91d42023-08-29 10:14:2547 # This part is from cros-kernel.eclass
Pi-Hsun Shihd3121bb2020-07-09 07:41:1248 # Support 64bit kernels w/32bit userlands.
49 local cross=${CHOST}
50 if [[ "${ARCH}:${kernel_arch}" == "arm:arm64" ]]; then
51 cross="aarch64-cros-linux-gnu"
52 fi
53
54 # Note: This would point to some temporary path if the kernel is not worked
55 # on, but it's ok since the decode_stacktrace.sh only use this path to strip
56 # the output.
57 #
58 # This is also why we always use the decode_stacktrace.sh from
59 # kernel/upstream instead of using the one in kernel_source_path.
60 local kernel_source_path
61 kernel_source_path=$(
Fei Shao597747e2023-01-05 04:34:2562 objdump -WL "/build/${board}/usr/lib/debug/boot/vmlinux" 2>/dev/null |
Pi-Hsun Shihd3121bb2020-07-09 07:41:1263 grep 'include/linux/compiler.h:$' |
64 head -1 |
65 sed 's|\(.*\)/include/linux/compiler.h:$|\1|')
66
Stephen Boyd0a36f432021-12-01 00:56:3567 ARCH=${kernel_arch} CROSS_COMPILE="${cross}-" \
Pi-Hsun Shihd3121bb2020-07-09 07:41:1268 "${SRC_ROOT}/third_party/kernel/upstream/scripts/decode_stacktrace.sh" \
69 "/build/${board}/usr/lib/debug/boot/vmlinux" \
70 "${kernel_source_path}" \
71 "/build/${board}/usr/lib/debug/lib/modules/"*/
72}
73
74main() {
75 if [[ -z "${FLAGS_board}" ]]; then
76 die "-b or --board required."
77 fi
78
79 decode_stacktrace "${FLAGS_board}" "$@"
80}
81
82main "$@"