forked from OERV-BSP/image-builder
optimize logging
This commit is contained in:
1
Makefile
1
Makefile
@@ -7,6 +7,7 @@ default: all
|
||||
# Configurable options
|
||||
CONTAINER_CMD ?= docker
|
||||
CONTAINER_IMAGE_TAG ?= imagebuilder-openeuler-24.03-lts
|
||||
LOG_LEVEL ?= INFO
|
||||
|
||||
define stack_include
|
||||
#$$(info Makefile "$$(lastword $$(MAKEFILE_STACK))" includes "$1")
|
||||
|
||||
@@ -107,7 +107,7 @@ $$($$(DISTRO_NAME)_$$(RELEASE_NAME)_$$(RECEIPE_NAME)_ARTIFACT): | $(STAGING_DIR)
|
||||
/bin/sh -c ' \
|
||||
mkdir /tmp/rootfs && \
|
||||
cd /image-builder/tools && \
|
||||
./build_rootfs.sh -i /image-builder/receipe -o /tmp/rootfs -p $$(PACKAGE_MANAGER) && \
|
||||
LOG_LEVEL=$(LOG_LEVEL) ./build_rootfs.sh -i /image-builder/receipe -o /tmp/rootfs -p $$(PACKAGE_MANAGER) && \
|
||||
export OUTPUT_ARCHIVE=/image-builder/output/$$$$(notdir $$$$@) && \
|
||||
export ROOTFS_DIR=/tmp/rootfs && \
|
||||
$$(COMPRESSION_CMD)'
|
||||
@@ -178,9 +178,8 @@ $$(DISTRO_NAME)-$$(RELEASE_NAME)-$$(1)-$$(DEVICE_NAME)-$$(PROFILE_NAME): $(STAGI
|
||||
-v $$($$(DISTRO_NAME)_$$(RELEASE_NAME)_$$(1)_ARTIFACT):/image-builder/$$(notdir $$($$(DISTRO_NAME)_$$(RELEASE_NAME)_$$(1)_ARTIFACT)):ro \
|
||||
-v $(DIST_DIR)/$$(DISTRO_NAME)/$$(RELEASE_NAME)/$$(DEVICE_NAME):/image-builder/output \
|
||||
$(CONTAINER_IMAGE_TAG) \
|
||||
/bin/sh -c ' set -x && \
|
||||
cd /image-builder/tools && \
|
||||
LOG_LEVEL=DEBUG ./build_bsp.sh -i /image-builder/receipe -s /image-builder/$$(notdir $$($$(DISTRO_NAME)_$$(RELEASE_NAME)_$$(1)_ARTIFACT)) -o /image-builder/output/$$(DISTRO_NAME)-$$(RELEASE_NAME)-$$(1)-$$(DEVICE_NAME)-$$(PROFILE_NAME) -p $$(PACKAGE_MANAGER)'
|
||||
/bin/sh -c 'cd /image-builder/tools && \
|
||||
LOG_LEVEL=$(LOG_LEVEL) ./build_bsp.sh -i /image-builder/receipe -s /image-builder/$$(notdir $$($$(DISTRO_NAME)_$$(RELEASE_NAME)_$$(1)_ARTIFACT)) -o /image-builder/output/$$(DISTRO_NAME)-$$(RELEASE_NAME)-$$(1)-$$(DEVICE_NAME)-$$(PROFILE_NAME) -p $$(PACKAGE_MANAGER)'
|
||||
|
||||
ifneq ($$$$(wildcard $$(BSP_PROFILE_DIR)/extensions/$$(1)/.),)
|
||||
# corresponding extension exists
|
||||
|
||||
@@ -88,6 +88,8 @@ main() {
|
||||
|
||||
generate_rootfs
|
||||
|
||||
logi "RootFS generated at: ${ROOTFS_DIR}"
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ filesystem_set_uuid_ext4() {
|
||||
loge "Invalid ext4 serial number: ${uuid}"
|
||||
exit 1
|
||||
fi
|
||||
tune2fs -U "${uuid}" "${device}"
|
||||
logcmd tune2fs -U "${uuid}" "${device}"
|
||||
}
|
||||
|
||||
filesystem_make_fs_ext4() {
|
||||
mkfs.ext4 "${1}"
|
||||
logcmd mkfs.ext4 "${1}"
|
||||
}
|
||||
|
||||
filesystem_shrink_ext4() {
|
||||
e2fsck -y -f "${1}"
|
||||
for i in $(seq 1 10); do resize2fs -M "${1}"; done
|
||||
logcmd e2fsck -y -f "${1}"
|
||||
for i in $(seq 1 10); do logcmd resize2fs -M "${1}"; done
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ filesystem_set_uuid_vfat() {
|
||||
loge "Invalid vfat serial number: ${uuid}"
|
||||
exit 1
|
||||
fi
|
||||
mlabel -N "$(echo "${uuid}" | tr -d '-')" -i "${device}"
|
||||
logcmd mlabel -N "$(echo "${uuid}" | tr -d '-')" -i "${device}"
|
||||
}
|
||||
|
||||
filesystem_make_fs_vfat() {
|
||||
mkfs.vfat "${1}"
|
||||
logcmd mkfs.vfat "${1}"
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ create_fs_mountpoint_content() {
|
||||
prepare_fs_blocks
|
||||
# Restore plain rootfs onto structured mountpoint
|
||||
logi "Copy files"
|
||||
rsync -ah "${ROOTFS_DIR}/" "${ROOTFS_MNT}"
|
||||
logcmd rsync -avh "${ROOTFS_DIR}/" "${ROOTFS_MNT}"
|
||||
# Umount and shrink (if necessary)
|
||||
post_fs_blocks
|
||||
|
||||
|
||||
@@ -35,6 +35,14 @@ __logprint() {
|
||||
__logprintraw "${formated_msg}"
|
||||
}
|
||||
|
||||
logcmd() {
|
||||
if [ "$(__logparselevel)" -le "$LOGLEVEL_DEBUG" ]; then
|
||||
{ "$@" ;}
|
||||
else
|
||||
{ "$@" >/dev/null 2>&1;}
|
||||
fi
|
||||
}
|
||||
|
||||
logd() {
|
||||
if [ "$(__logparselevel)" -le "$LOGLEVEL_DEBUG" ]; then
|
||||
__logprint "[DEBUG]" "$1"
|
||||
|
||||
@@ -85,7 +85,7 @@ handle_set_uuid() {
|
||||
new_uuid="$(uuidgen)"
|
||||
fi
|
||||
logd "Setting new UUID for part ${partid}: ${new_uuid}"
|
||||
1>/dev/null sgdisk -u "${partid}:${new_uuid}" "${TARGET_FILE}"
|
||||
logcmd sgdisk -u "${partid}:${new_uuid}" "${TARGET_FILE}"
|
||||
}
|
||||
|
||||
handle_set_type() {
|
||||
@@ -121,13 +121,13 @@ handle_set_type() {
|
||||
"
|
||||
done
|
||||
logd "Set type code for part ${partid}: ${typecode}"
|
||||
1>/dev/null sgdisk -t "${partid}:${typecode}" "${TARGET_FILE}"
|
||||
logcmd sgdisk -t "${partid}:${typecode}" "${TARGET_FILE}"
|
||||
printf '%s' "${typeattrbits}" | while read -r attrbit ; do
|
||||
if [ -z "${attrbit}" ]; then
|
||||
continue
|
||||
fi
|
||||
logd "Set partition attribute bit for part ${partid}: ${attrbit}"
|
||||
1>/dev/null sgdisk -A "${partid}:set:${attrbit}" "${TARGET_FILE}"
|
||||
logcmd sgdisk -A "${partid}:set:${attrbit}" "${TARGET_FILE}"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ handle_set_name() {
|
||||
exit 2
|
||||
fi
|
||||
partname="$1"; shift 1
|
||||
1>/dev/null sgdisk -c "${partid}:${partname}" "${TARGET_FILE}"
|
||||
logcmd sgdisk -c "${partid}:${partname}" "${TARGET_FILE}"
|
||||
}
|
||||
|
||||
print_usage() {
|
||||
|
||||
@@ -161,7 +161,7 @@ produce_image_GUID() {
|
||||
rm -f "${OUTPUT_IMAGE}"
|
||||
logi "Allocating ${final_disk_size}B for ${OUTPUT_IMAGE}"
|
||||
truncate -s "${final_disk_size}" "${OUTPUT_IMAGE}"
|
||||
sgdisk -Z "${OUTPUT_IMAGE}" >/dev/null 2>&1
|
||||
logcmd sgdisk -Z "${OUTPUT_IMAGE}"
|
||||
# sgdisk operates on files that may have different sector size with out target image
|
||||
SECTOR_SIZE="$(sgdisk -p "${OUTPUT_IMAGE}" | sed -rn 's/Sector size \(logical\): ([0-9]+) bytes/\1/p')"
|
||||
# Make sure our offset alignment satisfies sector size
|
||||
@@ -180,7 +180,7 @@ produce_image_GUID() {
|
||||
fi
|
||||
curr_part_offset="PARTITION_${part_idx}_OFFSET"
|
||||
curr_part_offset="${!curr_part_offset}"
|
||||
sgdisk --new "${part_idx}:$(( curr_part_offset / SECTOR_SIZE )):+$(( curr_part_size / SECTOR_SIZE ))" "${OUTPUT_IMAGE}" >/dev/null 2>&1
|
||||
logcmd sgdisk --new "${part_idx}:$(( curr_part_offset / SECTOR_SIZE )):+$(( curr_part_size / SECTOR_SIZE ))" "${OUTPUT_IMAGE}"
|
||||
curr_part_uuid="PARTITION_${part_idx}_UUID"
|
||||
curr_part_uuid="${!curr_part_uuid}"
|
||||
./partition_table_helper/gptcfg.sh "${OUTPUT_IMAGE}" set-uuid "${part_idx}" "${curr_part_uuid}"
|
||||
@@ -196,7 +196,8 @@ produce_image_GUID() {
|
||||
# Filling contents
|
||||
curr_part_content="PARTITION_${part_idx}_CONTENT"
|
||||
curr_part_content="${!curr_part_content}"
|
||||
dd conv=notrunc,sparse status=none \
|
||||
logi "Filling partition with ${curr_part_content}"
|
||||
logcmd dd conv=notrunc,sparse \
|
||||
if="${curr_part_content}" \
|
||||
of="${OUTPUT_IMAGE}" \
|
||||
bs="${GUID_TABLE_SECTOR_SIZE}" \
|
||||
|
||||
@@ -33,7 +33,7 @@ ${line}/entry.sh"
|
||||
}
|
||||
|
||||
install_package_cleanup_yum() {
|
||||
yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" clean all
|
||||
logcmd yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" clean all
|
||||
}
|
||||
|
||||
install_package_cleanup() {
|
||||
@@ -48,7 +48,7 @@ install_package_cleanup() {
|
||||
|
||||
install_package_list_yum() {
|
||||
# shellcheck shell=dash disable=SC2086
|
||||
yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" -y install $1
|
||||
logcmd yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" -y install $1
|
||||
}
|
||||
|
||||
install_package_list() {
|
||||
@@ -63,7 +63,7 @@ install_package_list() {
|
||||
|
||||
install_package_group_yum() {
|
||||
# shellcheck shell=dash disable=SC2086
|
||||
yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" -y groupinstall $1
|
||||
logcmd yum --forcearch riscv64 --installroot="${ROOTFS_DIR}" -y groupinstall $1
|
||||
}
|
||||
|
||||
install_package_group() {
|
||||
|
||||
Reference in New Issue
Block a user