Files
BPI-CM9-Linux/aml-patches/amlbian/0006-logcat-devtool-logcat-build-init-1-1.patch
T
2026-08-24 10:03:24 +08:00

568 lines
19 KiB
Diff

From e1b1ebe197734816b7d84049cf058dc5375ec310 Mon Sep 17 00:00:00 2001
From: "chunfei.wang" <chunfei.wang@amlogic.com>
Date: Thu, 25 Jun 2026 11:15:16 +0000
Subject: [PATCH 6/6] logcat: devtool logcat build init [1/1]
PD#SWPL-275381
Problem:
devtool logcat not build
Solution:
logcat build init
Fixed conflicts:
NA
Verify:
A9
Change-Id: If0acee48f204fb30c9df9c972cfed8287ebe19a5
Signed-off-by: chunfei.wang <chunfei.wang@amlogic.com>
---
config/boards/include/amlogic_common.inc | 1 +
extensions/amlogic-overlay.sh | 3 +
lib/function-img.sh | 11 +
.../android-tools-logcat/build-logcat.sh | 422 ++++++++++++++++++
.../android-tools-logcat/files/logcat.patch | 43 ++
5 files changed, 480 insertions(+)
create mode 100755 scripts/devtools/android-tools-logcat/build-logcat.sh
create mode 100755 scripts/devtools/android-tools-logcat/files/logcat.patch
diff --git a/config/boards/include/amlogic_common.inc b/config/boards/include/amlogic_common.inc
index fee9e72..b012e32 100644
--- a/config/boards/include/amlogic_common.inc
+++ b/config/boards/include/amlogic_common.inc
@@ -64,6 +64,7 @@ BUILD_UNITS=(
gst-aml-vendor
isp
tvserver
+ devtool
)
else
# Note: BUILD_UNITS is transformed into an array during processing.
diff --git a/extensions/amlogic-overlay.sh b/extensions/amlogic-overlay.sh
index 4e568f6..cc4b30f 100644
--- a/extensions/amlogic-overlay.sh
+++ b/extensions/amlogic-overlay.sh
@@ -249,6 +249,9 @@ function load_local_source() {
display_alert "AMLOGIC" ">> Start build linux-uapi-headers " "info"
source "${EXTENSION_DIR}/../scripts/build-linux-uapi-headers.sh"
+ display_alert "AMLOGIC" ">> Start build logcat " "info"
+ source "${EXTENSION_DIR}/../scripts/devtools/android-tools-logcat/build-logcat.sh"
+
if ! is_unit_enabled "rootfs"; then
echo "rootfs NOT in BUILD_UNITS, exit immediately"
exit 1
diff --git a/lib/function-img.sh b/lib/function-img.sh
index c79cdbd..9afa448 100644
--- a/lib/function-img.sh
+++ b/lib/function-img.sh
@@ -329,6 +329,16 @@ function install_tvserver_deb {
install_aml_deb $ubootenv_file
}
+function install_logcat_deb {
+ if ! is_unit_enabled "devtool" || ! is_unit_enabled "liblog"; then
+ display_alert "[SKIP] >> devtool android tool logcat disabled ( not install)" "" "info"
+ return
+ fi
+
+ local logcat_file=$(find "${BUILD_DEBS}" -name "android-tools-logcat*.deb" 2>/dev/null)
+ install_aml_deb $logcat_file
+}
+
function install_common() {
display_alert "install amlogic debs: GPU/NPU/DEC/ENC/... ... " "IMG" "info"
@@ -378,6 +388,7 @@ function install_common() {
install_media_deb
install_tvserver_deb
+ install_logcat_deb
if [[ $(type -t tweaks_platform) == function ]]; then
tweaks_platform
diff --git a/scripts/devtools/android-tools-logcat/build-logcat.sh b/scripts/devtools/android-tools-logcat/build-logcat.sh
new file mode 100755
index 0000000..0f8ef22
--- /dev/null
+++ b/scripts/devtools/android-tools-logcat/build-logcat.sh
@@ -0,0 +1,422 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
+# Copyright (C) 2026 Amlogic, Inc. All rights reserved
+################################################################################
+# Amlbian Logcat Compilation Module
+#
+# Purpose: Compile and package logcat tool for Android debugging
+# Provides: logcat binary for system logging
+################################################################################
+
+set -e
+
+# Get script directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+AMLBIAN_DIR="$(dirname "$(dirname "$(dirname "${SCRIPT_DIR}")")")"
+BASE_DIR="$(dirname "$(dirname "${AMLBIAN_DIR}")")"
+
+# Source common functions
+if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then
+ source "${AMLBIAN_DIR}/lib/function-common.sh"
+fi
+
+# ==============================================================================
+# Shared Helper Functions
+# ==============================================================================
+
+# ------------------------------------------------------------------------------
+# Step 1: Version and Package Information Definition
+# ------------------------------------------------------------------------------
+
+# Initialize common package metadata for logcat
+function _logcat_init_package_info() {
+ PKG_MAINTAINER="Armbian Build <build@armbian.com>"
+ PKG_DESCRIPTION="Android logcat tool for system logging"
+ PKG_NAME="android-tools-logcat"
+ PKG_VERSION="1.0"
+ PKG_ARCH="all"
+
+ # Source directory for logcat
+ LOGCAT_SRC_DIR="${BASE_DIR}/aml-comp/vendor/amlogic/aml_commonlib/logcat"
+ FILES_DIR="${SCRIPT_DIR}/files"
+}
+
+# ------------------------------------------------------------------------------
+# Step 2: Build Directory Structure Setup
+# ------------------------------------------------------------------------------
+
+# Create layered build directory structure
+# Parameters:
+# $1 - base name (e.g. "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}")
+# Sets: TMP_DIR, BASE_BUILD_DIR, SOURCE_DIR, BUILD_DIR, INSTALL_DIR, PATCH_DIR,
+# DEB_PACKAGE_DIR, DEBIAN_DIR
+function _logcat_create_build_dirs() {
+ local base_name="$1"
+
+ TMP_DIR="${SRC}/.tmp"
+ mkdir -p "${TMP_DIR}"
+
+ # 基础构建目录
+ BASE_BUILD_DIR="${TMP_DIR}/${base_name}"
+
+ rm -rf ${BASE_BUILD_DIR}
+ # 分层目录
+ SOURCE_DIR="${BASE_BUILD_DIR}/source" # 源码目录
+ BUILD_DIR="${BASE_BUILD_DIR}/build" # 编译目录
+ INSTALL_DIR="${BASE_BUILD_DIR}/install" # 安装目录
+ PATCH_DIR="${BASE_BUILD_DIR}/patch" # 补丁目录
+
+ # 创建所有目录
+ mkdir -p "${SOURCE_DIR}"
+ mkdir -p "${BUILD_DIR}"
+ mkdir -p "${INSTALL_DIR}"
+ mkdir -p "${PATCH_DIR}"
+
+ # 在BUILD_DIR下创建deb/包名目录
+ DEB_PACKAGE_DIR="${BUILD_DIR}/deb/${base_name}"
+ mkdir -p "${DEB_PACKAGE_DIR}"
+
+ # 安装目录的子目录
+ DEBIAN_DIR="${INSTALL_DIR}/DEBIAN"
+ mkdir -p "${DEBIAN_DIR}"
+}
+
+# Create standard install subdirectories for logcat
+function _logcat_create_install_dirs() {
+ mkdir -p "${INSTALL_DIR}/usr/bin"
+}
+
+# ------------------------------------------------------------------------------
+# Step 3: Debian Packaging Scripts Creation
+# ------------------------------------------------------------------------------
+
+# Create Debian control file
+# Parameters:
+# $1 - package name
+# $2 - package version
+# $3 - package architecture
+# $4 - maintainer
+# $5 - description
+# $6 - section (optional, default "utils")
+function _logcat_create_control_file() {
+ local pkg_name="$1"
+ local pkg_version="$2"
+ local pkg_arch="$3"
+ local maintainer="$4"
+ local description="$5"
+ local section="${6:-utils}"
+
+ display_alert "COMPILE-LOGCAT Creating control file DEBIAN/control" "info"
+ cat > "${DEBIAN_DIR}/control" <<EOF
+Package: ${pkg_name}
+Version: ${pkg_version}
+Architecture: ${pkg_arch}
+Maintainer: ${maintainer}
+Depends: liblog
+Section: ${section}
+Priority: optional
+Description: ${description}
+ Android logcat tool for viewing system logs.
+ Useful for debugging Android-based systems.
+EOF
+}
+
+# Create postinst script for logcat
+function _logcat_create_postinst() {
+ display_alert "COMPILE-LOGCAT Creating post-installation script DEBIAN/postinst" "info"
+ cat > "${DEBIAN_DIR}/postinst" << EOF
+#!/bin/sh
+set -e
+
+if [ "\$1" = "configure" ]; then
+ echo "Logcat tool installed successfully"
+ echo "Usage: logcat [options]"
+fi
+
+exit 0
+EOF
+ chmod 755 "${DEBIAN_DIR}/postinst"
+}
+
+# Create prerm script for logcat
+function _logcat_create_prerm() {
+ display_alert "COMPILE-LOGCAT Creating pre-removal script DEBIAN/prerm" "info"
+ cat > "${DEBIAN_DIR}/prerm" << EOF
+#!/bin/sh
+set -e
+
+if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
+ echo "Logcat tool being removed"
+fi
+
+exit 0
+EOF
+ chmod 755 "${DEBIAN_DIR}/prerm"
+}
+
+# ------------------------------------------------------------------------------
+# Step 4: Source/Vendor File Copying and Patching
+# ------------------------------------------------------------------------------
+
+# Copy logcat source files and apply patches
+function _logcat_copy_and_patch_files() {
+ display_alert "COMPILE-LOGCAT Copying source files from ${LOGCAT_SRC_DIR}" "info"
+
+ # Check if source directory exists
+ if [[ ! -d "${LOGCAT_SRC_DIR}" ]]; then
+ display_alert "COMPILE-LOGCAT Source directory not found: ${LOGCAT_SRC_DIR}" "err"
+ display_alert "COMPILE-LOGCAT Trying to clone or find alternative source" "info"
+ # Try to find source in other locations
+ LOGCAT_SRC_DIR="${BASE_DIR}/aml-comp/vendor/amlogic/aml_commonlib/logcat"
+ if [[ ! -d "${LOGCAT_SRC_DIR}" ]]; then
+ display_alert "COMPILE-LOGCAT Source not found. Please ensure aml_commonlib is available" "err"
+ exit 1
+ fi
+ fi
+
+ # Copy source files
+ cp -r "${LOGCAT_SRC_DIR}" "${SOURCE_DIR}/logcat"
+ display_alert "COMPILE-LOGCAT Copied logcat source files" "info"
+
+ # Apply patches if available
+ if [[ -f "${FILES_DIR}/logcat.patch" ]]; then
+ display_alert "COMPILE-LOGCAT Applying logcat.patch" "info"
+ cd "${SOURCE_DIR}"
+ patch -p1 < "${FILES_DIR}/logcat.patch" || true
+ cd - > /dev/null
+ fi
+}
+
+# ------------------------------------------------------------------------------
+# Step 5: Liblog Dependency Handling
+# ------------------------------------------------------------------------------
+
+# Check and build liblog dependency if needed
+function _logcat_check_liblog_dependency() {
+ display_alert "COMPILE-LOGCAT Checking liblog dependency" "info"
+
+ # Check if liblog is already built
+ local liblog_dir="${SRC}/.tmp/liblog-build-${ARCH:-arm64}"
+ local liblog_install_dir="${liblog_dir}/install"
+
+ if [[ ! -d "${liblog_install_dir}" ]] || [[ ! -f "${liblog_install_dir}/usr/lib/liblog.so" ]]; then
+ display_alert "COMPILE-LOGCAT liblog not found, building liblog..." "info"
+
+ # Build liblog
+ if ! (
+ cd "${AMLBIAN_DIR}"
+ source "${AMLBIAN_DIR}/scripts/build-liblog.sh"
+ ); then
+ display_alert "COMPILE-LOGCAT Failed to build liblog" "err"
+ return 1
+ fi
+
+ # Verify liblog was built
+ if [[ ! -d "${liblog_install_dir}" ]] || [[ ! -f "${liblog_install_dir}/usr/lib/liblog.so" ]]; then
+ display_alert "COMPILE-LOGCAT liblog still not found after build" "err"
+ return 1
+ fi
+ fi
+
+ display_alert "COMPILE-LOGCAT liblog dependency satisfied" "info"
+ return 0
+}
+
+# ------------------------------------------------------------------------------
+# Step 6: Compilation
+# ------------------------------------------------------------------------------
+
+# Compile logcat tool
+function _logcat_compile() {
+ display_alert "COMPILE-LOGCAT Compiling logcat tool" "info"
+
+ # First check and build liblog dependency
+ if ! _logcat_check_liblog_dependency; then
+ display_alert "COMPILE-LOGCAT Cannot compile without liblog" "err"
+ exit 1
+ fi
+
+ # Get liblog paths
+ local liblog_dir="${SRC}/.tmp/liblog-build-${ARCH:-arm64}"
+ local liblog_install_dir="${liblog_dir}/install"
+
+ cd "${SOURCE_DIR}/logcat"
+
+ # Set up build environment with liblog paths
+ export OUT_DIR="${BUILD_DIR}"
+ export TARGET_DIR="${INSTALL_DIR}"
+ export STAGING_DIR="${STAGING_DIR_TARGET:-${BASE_DIR}/staging}"
+ export DESTDIR="${INSTALL_DIR}"
+
+ # Add liblog include and library paths
+ export CFLAGS="-I${SOURCE_DIR}/logcat/include"
+ export LDFLAGS="-L${liblog_install_dir}/usr/lib -llog"
+
+ # Create necessary directories
+ mkdir -p "${BUILD_DIR}"
+ mkdir -p "${STAGING_DIR}"
+
+ # Create a temporary Makefile override to fix logcat_test compilation
+ # The original Makefile doesn't include $(CFLAGS) in the logcat_test rule
+ local makefile_override="${TMP_DIR}/logcat-override.mk"
+ cat > "${makefile_override}" << 'EOF'
+# Makefile override for logcat_test compilation
+# Fixes the missing $(CFLAGS) in the original rule
+
+# Override the logcat_test rule to include $(CFLAGS)
+logcat_test: logcat_test.c
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $(OUT_DIR)/$@
+EOF
+
+ # Compile with liblog support, using both the original Makefile and the override
+ # Use -f to specify multiple makefiles: original Makefile first, then override
+ make -C "${SOURCE_DIR}/logcat" \
+ OUT_DIR="${BUILD_DIR}" \
+ TARGET_DIR="${INSTALL_DIR}" \
+ STAGING_DIR="${STAGING_DIR}" \
+ DESTDIR="${INSTALL_DIR}" \
+ CFLAGS="${CFLAGS} -DHAVE_IOCTL" \
+ LDFLAGS="${LDFLAGS}" \
+ -f Makefile -f "${makefile_override}"
+
+ cd - > /dev/null
+
+ # Check if compilation succeeded
+ if [[ ! -f "${BUILD_DIR}/logcat" ]]; then
+ display_alert "COMPILE-LOGCAT Compilation failed: logcat binary not found" "err"
+ exit 1
+ fi
+
+ display_alert "COMPILE-LOGCAT Compilation successful" "info"
+}
+
+# ------------------------------------------------------------------------------
+# Step 7: Installation
+# ------------------------------------------------------------------------------
+
+# Install logcat binaries
+function _logcat_install() {
+ display_alert "COMPILE-LOGCAT Installing binaries" "info"
+
+ # Create bin directory
+ mkdir -p "${INSTALL_DIR}/usr/bin"
+
+ # Install logcat binary
+ if [[ -f "${BUILD_DIR}/logcat" ]]; then
+ install -m 0755 "${BUILD_DIR}/logcat" "${INSTALL_DIR}/usr/bin/"
+ display_alert "COMPILE-LOGCAT Installed logcat binary" "info"
+ else
+ display_alert "COMPILE-LOGCAT logcat binary not found in ${BUILD_DIR}" "err"
+ exit 1
+ fi
+
+ # Install logcat_test if available
+ if [[ -f "${BUILD_DIR}/logcat_test" ]]; then
+ install -m 0755 "${BUILD_DIR}/logcat_test" "${INSTALL_DIR}/usr/bin/"
+ display_alert "COMPILE-LOGCAT Installed logcat_test binary" "info"
+ fi
+}
+
+# ------------------------------------------------------------------------------
+# Step 8: Debian Package Building
+# ------------------------------------------------------------------------------
+
+# Build Debian package from install directory
+# Parameters:
+# $1 - log prefix (e.g. "COMPILE-LOGCAT")
+# $2 - output deb filename (without path)
+# Sets: OUTPUT_DEB
+function _logcat_build_deb_package() {
+ local log_prefix="$1"
+ local output_deb_name="$2"
+
+ # 将install目录内容拷贝到deb目录
+ display_alert "Copying install directory to deb package directory ${log_prefix}" "info"
+ cp -r "${INSTALL_DIR}/"* "${DEB_PACKAGE_DIR}/" 2>&1
+
+ # 基于deb目录打包
+ display_alert "Building Debian package from deb directory ${log_prefix}" "info"
+ dpkg-deb --build "${DEB_PACKAGE_DIR}" 2>&1
+
+ # Move to output directory
+ OUTPUT_DEB="${SRC}/output/${output_deb_name}"
+ mkdir -p "$(dirname "${OUTPUT_DEB}")"
+ mv "${DEB_PACKAGE_DIR}.deb" "${OUTPUT_DEB}"
+
+ display_alert "${log_prefix} Package built successfully ${output_deb_name}" "info"
+ display_alert "${log_prefix} Build directory preserved ${BASE_BUILD_DIR}" "info"
+}
+
+# Display build directory info
+# Parameters:
+# $1 - log prefix
+function _logcat_display_build_info() {
+ local log_prefix="$1"
+ display_alert "${log_prefix} Source dir: ${SOURCE_DIR}" "info"
+ display_alert "${log_prefix} Build dir: ${BUILD_DIR}" "info"
+ display_alert "${log_prefix} Install dir: ${INSTALL_DIR}" "info"
+ display_alert "${log_prefix} Patch dir: ${PATCH_DIR}" "info"
+ display_alert "${log_prefix} Deb package dir: ${DEB_PACKAGE_DIR}" "info"
+ display_alert "${log_prefix} Logcat source dir: ${LOGCAT_SRC_DIR}" "info"
+}
+
+# ==============================================================================
+# Main Build Functions (Entry Points - DO NOT RENAME)
+# ==============================================================================
+
+# ------------------------------------------------------------------------------
+# Logcat Tool Build
+# Entry point: amlbian_build_logcat
+# ------------------------------------------------------------------------------
+
+function amlbian_build_logcat() {
+
+ if ! is_unit_enabled "devtool" || ! is_unit_enabled "liblog"; then
+ echo "[SKIP] >> Logcat disable in BUILD_UNITS"
+ return
+ fi
+
+ # ---- Step 1: Version and Package Information ----
+ _logcat_init_package_info
+
+ # ---- Step 2: Build Directory Setup ----
+ _logcat_create_build_dirs "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
+ _logcat_create_install_dirs
+
+ # Display info
+ display_alert "COMPILE-LOGCAT Building logcat tool package version ${PKG_VERSION}" "info"
+ _logcat_display_build_info "COMPILE-LOGCAT"
+
+ # ---- Step 3: Debian Packaging Scripts ----
+ _logcat_create_control_file \
+ "${PKG_NAME}" "${PKG_VERSION}" "${PKG_ARCH}" "${PKG_MAINTAINER}" \
+ "${PKG_DESCRIPTION}" "utils"
+
+ _logcat_create_postinst
+ _logcat_create_prerm
+
+ # ---- Step 4: Copy Source/Vendor Files and Apply Patches ----
+ _logcat_copy_and_patch_files
+
+ # ---- Step 5: Check and Build Liblog Dependency ----
+ if ! _logcat_check_liblog_dependency; then
+ display_alert "COMPILE-LOGCAT Cannot proceed without liblog" "err"
+ return 1
+ fi
+
+ # ---- Step 6: Compilation ----
+ _logcat_compile
+
+ # ---- Step 7: Installation ----
+ _logcat_install
+
+ # ---- Step 8: Build Debian Package ----
+ _logcat_build_deb_package "COMPILE-LOGCAT" "${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}.deb"
+
+ display_alert "COMPILE-LOGCAT Logcat tool build completed successfully" "info"
+ return 0
+}
+
+display_alert "AMLbian Logcat Build Script" "Scriptdir: ${SCRIPT_DIR} AmlbianDir: ${AMLBIAN_DIR}" "info"
+amlbian_build_logcat
+display_alert "AMLOGIC: logcat build completed" "${OUTPUT_DIR}" "info"
\ No newline at end of file
diff --git a/scripts/devtools/android-tools-logcat/files/logcat.patch b/scripts/devtools/android-tools-logcat/files/logcat.patch
new file mode 100755
index 0000000..68633fa
--- /dev/null
+++ b/scripts/devtools/android-tools-logcat/files/logcat.patch
@@ -0,0 +1,43 @@
+diff --git a/logcat/Makefile b/logcat/Makefile
+index 19a47c5..ccdfd7e 100644
+--- a/logcat/Makefile
++++ b/logcat/Makefile
+@@ -7,15 +7,19 @@ OBJ = logcat.o
+ CFLAGS = -Wall -Wextra -I $(LOGCAT_DIR)/include -DHAVE_IOCTL
+ LDFLAGS = -L$(STAGING_DIR)/usr/lib -llog
+ TARGET=logcat
++TEST := logcat_test
+
+ # rules
+-all: $(TARGET)
++all: $(TARGET) $(TEST)
+
+ $(TARGET): $(OBJ)
++ $(CXX) $(LDFLAGS) $^ -o $@
++
++$(TEST): logcat_test.c
+ $(CC) $(LDFLAGS) $^ -o $@
+
+ %.o: %.cpp
+- $(CC) -c $(CFLAGS) $^ -o $@
++ $(CXX) -c $(CFLAGS) $^ -o $@
+
+ .PHONY: clean
+
+diff --git a/logcat/logcat_test.c b/logcat/logcat_test.c
+new file mode 100644
+index 0000000..b48bcdb
+--- /dev/null
++++ b/logcat/logcat_test.c
+@@ -0,0 +1,11 @@
++#include <stdio.h>
++#include <cutils/log.h>
++#include <unistd.h>
++
++int main(int argc, char ** argv){
++ while (1){
++ sleep(1);
++ ALOGE("abert %s: test======>%d \n", __FUNCTION__, __LINE__);
++ }
++ return 0;
++}
--
2.25.1