Skip to content

Commit

Permalink
Replace yq with parse_dtbo_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeChenL authored and RadxaYuntian committed Jan 2, 2024
1 parent e4eed7d commit f5436b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Depends: device-tree-compiler,
parted,
pkexec | policykit-1 (<< 122-1),
whiptail,
yq,
python3,
python3-yaml,
u-boot-menu,
${misc:Depends},
Suggests: aicrf-test,
Expand Down
4 changes: 3 additions & 1 deletion src/usr/lib/rsetup/cli/u-boot-menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# shellcheck source=src/usr/lib/rsetup/mod/overlay.sh
source "/usr/lib/rsetup/mod/overlay.sh"

PARSE_DTBO_METADATA="/usr/lib/rsetup/mod/parse_dtbo_metadata"

ALLOWED_RCONFIG_FUNC+=("load_u-boot_setting")

check_overlay_conflict_init() {
Expand Down Expand Up @@ -135,7 +137,7 @@ rebuild_overlays() {

parse_dtbo() {
local output
output="$(dtc -I dtb -O dts "$1" 2>/dev/null | dtc -I dts -O yaml 2>/dev/null | yq -r ".[0].metadata.$2[0]" | tr '\0' '\n')"
output="$(dtc -I dtb -O dts "$1" 2>/dev/null | dtc -I dts -O yaml 2>/dev/null | "$PARSE_DTBO_METADATA" "$2")"

if (( $# >= 3 ))
then
Expand Down
12 changes: 12 additions & 0 deletions src/usr/lib/rsetup/mod/parse_dtbo_metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

from sys import argv, stdin
import yaml

yaml.CLoader.add_constructor('!u8', yaml.constructor.FullConstructor.construct_yaml_seq)

try:
print(yaml.load(stdin.read(), Loader=yaml.CLoader)[0]['metadata'][argv[1]][0].replace("\0", "\n"))
except KeyError as e:
print("null")

0 comments on commit f5436b1

Please sign in to comment.