hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
#
# Copyright (c) 2021 Rockchip Electronics Co., Ltd
#
# SPDX-License-Identifier: GPL-2.0
#
 
set -e
 
function usage()
{
   echo
   echo "usage:"
   echo "    $0 -f [Android boot.img] -o [Distro(ext2) boot.img]"
   echo
}
 
function args_process()
{
   if [ $# -ne 4 ]; then
       usage
       exit 1
   fi
 
   while [ $# -gt 0 ]; do
       case $1 in
           -f)
               BOOT_IMG=$2
               shift 2
               ;;
           -o)
               DISTRO_IMG=$2
               shift 2
               ;;
           *)
               usage
               exit 1
               ;;
       esac
   done
 
   if [ ! -f ${BOOT_IMG} ]; then
       echo "ERROR: No ${ITB}"
       exit 1
   fi
}
 
function android2distro()
{
   rm distro/ boot/ ${DISTRO_IMG} -rf
   mkdir -p boot
 
   ./scripts/unpack_bootimg --boot_img ${BOOT_IMG} --out distro/
   ./scripts/unpack_resource.sh distro/second distro/
   BOOTARGS=`fdtget -ts distro/rk-kernel.dtb /chosen bootargs`
 
   cp distro/rk-kernel.dtb boot/rk-kernel.dtb
   cp distro/kernel boot/kernel
   cp distro/ramdisk boot/ramdisk
   mkdir -p boot/extlinux
   touch boot/extlinux/extlinux.conf
   echo "label rockchip-linux-kernel" >> boot/extlinux/extlinux.conf
   echo "    kernel /kernel" >> boot/extlinux/extlinux.conf
   echo "    fdt /rk-kernel.dtb" >> boot/extlinux/extlinux.conf
   echo "    initrd /ramdisk" >> boot/extlinux/extlinux.conf
   echo "    append ${BOOTARGS}" >> boot/extlinux/extlinux.conf
 
   SIZE_KB=`ls -lh ${BOOT_IMG} | awk '{ print $5 }' | tr -d 'M'`
   SIZE_KB=`echo "scale=0;$SIZE_KB/1"|bc -l` # for align down integer
   SIZE_KB=`expr ${SIZE_KB} + 2 + 1`
   SIZE_BYTE=$((${SIZE_KB}*1024))
   genext2fs -b ${SIZE_BYTE} -B 1024 -d boot/ -i 8192 -U ${DISTRO_IMG}
 
   echo
   echo "Successful: ${DISTRO_IMG} is ready."
   echo
}
 
args_process $*
android2distro