diff --git a/telechips/README.md b/telechips/README.md new file mode 100644 index 0000000..6cdbfd8 --- /dev/null +++ b/telechips/README.md @@ -0,0 +1,63 @@ +# For telechips boards build scripts + + +### Guide + +1. 커스텀 커맨드 경로 설정 +``` +$ echo "export PATH=$HOME/.usr/bin:$PATH" >> ${HOME}/.profile +``` +``` +$ mkdir -p ${HOME}/.usr/bin +$ mkdir -p ${HOME}/.usr/share +``` +
+ +2. kernel-script 다운로드 +``` +$ git clone https://github.com/how2flow/kernel-scripts -b telechips +$ cp kernel-scripts/telechips/kernel-script ${HOME}/.usr/bin/kernel-script +$ cp kernel-scripts/telechips/scripts/* ${HOME}/.usr/share/kernel-scripts/ +``` +
+ +3. boot-firmware 세팅 + +``` +$ cd ${HOME} +$ git clone {boot-firmware repo} -b "타겟 보드(tcc807x / ..)" +$ cp kernel-scripts/telechips/boot-firmware/mksd.sh ${HOME}/boot-firmware +``` +
+ +4. ps1 파일 설정 +``` +kernel-scripts/telechips/fwdn/file-tree 참조 +``` +
+ +5. uboot / kernel 파일 트리 +
+ +u-boot +``` +~/u-boot/u-boot-core$ tree -L 1 +├── api +├── arch +├── board +├── boot +... +``` +
+ +kernel +``` +~/kernel$ tree -L 1 +. +├── initramfs64.cpio.lzo +├── initramfs.cpio.lzo +├── kernel-5.10 + `initramfs64.cpio.lzo -> ../initramfs64.cpio.lzo +... +``` +
diff --git a/telechips/boot-firmware/mksd.sh b/telechips/boot-firmware/mksd.sh new file mode 100755 index 0000000..f7a549b --- /dev/null +++ b/telechips/boot-firmware/mksd.sh @@ -0,0 +1,180 @@ +#!/bin/bash + +# This script must exist in root-path of 'boot-firmware/' +# written by Steve Jeong (steve@how2flow.net) + +#set -x + +CHIP=("tcc807x" "tcc897x") +K_VER="5.10" +KERNEL="${HOME}/kernel/kernel-${K_VER}/" +UBOOT="${HOME}/u-boot/u-boot-core/" + +cherrypick() { + local cherry + + cherry=$(find ${1} -name ${2} | grep ${3}) + if [ -z ${cherry} ]; then + cherry=$(find ${1} -name ${2}) + fi + + echo ${cherry} +} + +cherrynpick() { + local cherry + + cherry=$(find ${1} -name ${2} | grep -v ${3}) + if [ -z ${cherry} ]; then + cherry=$(find ${1} -name ${2}) + fi + + echo ${cherry} +} + +create_gpt_partition_list() { + local target + + target=${1} + + case ${target} in + tcc807x) + cat << __EOF > tools/mktcimg/gpt_partition.list +bl3_ap0_a:2048k@../ap0_bl3.rom +bl3_ap0_b:2048k@../ap0_bl3.rom +bl3_ap1_a:2048k@../ap1_bl3.rom +bl3_ap1_b:2048k@../ap1_bl3.rom +boot:40960k@../boot.img +dtb:1024k@../tcc8070-lpd4x322.dtb +misc:1024k@ +env:16k@ +subcore_boot:40960k@../boot_sub.img +subcore_dtb:1024k@../tcc8070-subcore-lpd4x322.dtb +subcore_misc:1024k@ +subcore_env:16k@ +data:0k@ +__EOF + UFS_SIZE=63988301824 + MMC_SIZE=31268536320 + sleep .5 + ;; + tcc897x) + cat << __EOF > tools/mktcimg/gpt_partition.list +bl3_ca7_a:2048k@../ca7_bl3.rom +bl3_ca7_b:2048k@../ca7_bl3.rom +boot:49152k@../boot.img +dtb:1024k@../tcc8971-lcn.dtb +env:1024k@ +misc:1024k@ +data:0k@ +__EOF +#7818182656 +#15636365312 + MMC_SIZE=7818182656 + sleep .5 + ;; + esac +} + +create_symlink() { + local data + local dtb_main + local dtb_sub + local idx + local kernel_main + local kernel_sub + local line + local path + local root_path + local target + local uboot + + data=$(cat tools/mktcimg/gpt_partition.list) + root_path=$(pwd -P) + cd tools/mktcimg/ + + for line in ${data}; do + idx=${line%%:*} + path=${line#*@} + target=${line#*/} + + if [ -z ${path} ]; then + continue + fi + + # u-boot: main is different with sub + if [ $(echo ${idx} | grep "bl" | wc -l) -gt 0 ]; then + uboot=$(cherrypick ${UBOOT} ${target} "build") + [ ! -f ${uboot} ] && echo "There is no ${target} in ${UBOOT}" + rm -rf ${path} && ln -s ${uboot} ${path} + # kernel: main is equal with sub + elif [ $(echo ${idx} | grep "boot" | wc -l) -gt 0 ]; then + # kernel-sub + if [ $(echo ${idx} | grep "sub" | wc -l) -eq 1 ]; then + kernel_sub=$(cherrypick ${KERNEL} ${target} "build_sub") + if [ -z ${kernel_sub} ]; then + kernel_sub=$(cherrypick ${KERNEL} ${target/_sub/} "build_sub") + mv ${kernel_sub} ${kernel_sub/.img/_sub.img} + kernel_sub=${kernel_sub/.img/_sub.img} + fi + [ ! -f ${kernel_sub} ] && echo "There is no ${target} in ${KERNEL}" + rm -rf ${path} && ln -s ${kernel_sub} ${path} + # kernel-main + else + kernel_main=$(cherrynpick ${KERNEL} ${target} "build_sub") + [ ! -f ${kernel_main} ] && echo "There is no ${target} in ${KERNEL}" + rm -rf ${path} && ln -s ${kernel_main} ${path} + fi + # dtb: main is equal with sub + elif [ $(echo ${idx} | grep "dtb" | wc -l) -gt 0 ]; then + # dtb-sub + if [ $(echo ${idx} | grep "sub" | wc -l) -eq 1 ]; then + dtb_sub=$(cherrypick ${KERNEL} ${target/_sub/} "build_sub") + [ ! -f ${dtb_sub} ] && echo "There is no ${target} in ${KERNEL}" + rm -rf ${path} && ln -s ${dtb_sub} ${path} + # dtb-main + else + dtb_main=$(cherrynpick ${KERNEL} ${target} "build_sub") + [ ! -f ${dtb_main} ] && echo "There is no ${target} in ${KERNEL}" + rm -rf ${path} && ln -s ${dtb_main} ${path} + fi + fi + + done + + cd ${root_path} +} + +make_sd() { + local root_path + local target + + root_path=$(pwd -P) + target=${1} + + cd tools/mktcimg/ + case ${target} in + ufs) # ufs + ./mktcimg --parttype gpt --storage_size ${UFS_SIZE} --fplist gpt_partition.list --outfile SD_Data.fai --area_name "SD Data" --gptfile SD_Data.gpt --sector_size 4096 + mv SD_Data* ${root_path} + ;; + *) # mmc + ./mktcimg --parttype gpt --storage_size ${MMC_SIZE} --fplist gpt_partition.list --outfile SD_Data.fai --area_name "SD Data" --gptfile SD_Data.gpt + mv SD_Data* ${root_path} + ;; + esac + + cd ${root_path} +} + +echo "=== Select Chip model ===" +for ((i=0; i<${#CHIP[@]}; i++)); do + echo "[$((i+1))] ${CHIP[$i]}" +done + +read -r -p "CHIP: " opt + +create_gpt_partition_list ${CHIP[$(expr ${opt} - 1)]} +create_symlink +sleep 3 +make_sd diff --git a/telechips/fwdn/FlashData_tcc807x.ps1 b/telechips/fwdn/FlashData_tcc807x.ps1 new file mode 100644 index 0000000..0ab1d68 --- /dev/null +++ b/telechips/fwdn/FlashData_tcc807x.ps1 @@ -0,0 +1,34 @@ +# This file is for window power shell script +# Need to change LF to CRLF +# related packages: dos2unix, unix2dos +# written by Steve Jeong (steve@how2flow.net) + +# Define the path to fwdn.exe +$fwdnExecutable = ".\fwdn.exe" + +# Define the directory path +$directoryPath = "Z:\boot-firmware" + +# Search for all files ending with fwdn.json and boot.json +$fwdnFiles = Get-ChildItem -Path $directoryPath -Filter "*fwdn.json" +$bootFiles = Get-ChildItem -Path $directoryPath -Filter "*boot.json" + +# Execute fwdn.json files +foreach ($file in $fwdnFiles) { + Write-Host "Executing file: $($file.FullName) (command: --fwdn)" + & $fwdnExecutable --fwdn $file.FullName +} + +# Execute boot.json files +foreach ($file in $bootFiles) { + Write-Host "Executing file: $($file.FullName) (command: --write)" + & $fwdnExecutable --write $file.FullName +} + +# Execute additional command +$additionalFile = "Z:\boot-firmware\SD_Data.fai" +$storageType = "emmc" +$storageArea = "user" + +Write-Host "Executing additional command: $additionalFile (command: --write --storage $storageType --area $storageArea)" +& $fwdnExecutable --write $additionalFile --storage $storageType --area $storageArea diff --git a/telechips/fwdn/file-tree b/telechips/fwdn/file-tree new file mode 100644 index 0000000..c649c4e --- /dev/null +++ b/telechips/fwdn/file-tree @@ -0,0 +1,12 @@ +└── Window (C:) + ├── samba (Z:) +    ├── boot-firmware/ + ├── fwnd.json + ├── boot.json + ├── SD_Data.fai + ├── SD_Data.gpt + ├── SD_Data.gpt.back + ├── SD_Data.gpt.prim + ├── ... + ├── tools/ + ├── ... diff --git a/telechips/kernel-script b/telechips/kernel-script new file mode 100755 index 0000000..4169c6b --- /dev/null +++ b/telechips/kernel-script @@ -0,0 +1,67 @@ +#!/bin/bash + +# Copyright (C) 2024 Steve Jeong +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see + +DEFAULT="${HOME}/.usr/share/kernel-scripts" +PREFIX=${CHECKOUT:-${DEFAULT}} + +options=$(getopt -o cfhil -l crosscompile,ftrace,help,install,losetup -- "$@") +eval set -- "${options}" + +Usage() { + echo "Usage: kernel-script [OPTIONS]" + echo "Options:" + echo " -c, --crosscompile Perform a cross-compilation of the kernel" + echo " -f, --ftrace Run ftrace with kernel APIs" + echo " need root permission" + echo " -l, --losetup Losetup in loop devices" + echo " need root permission" + echo " --help Display this help message" + exit 0 +} + +while true; do + case "$1" in + -c|--crosscompile) + . "${PREFIX}"/do_crosscompile + exit 0 + ;; + -f|--ftrace) + . "${PREFIX}"/do_ftrace + exit 0 + ;; + -h|--help) + Usage + ;; + -l|--losetup) + . "${PREFIX}"/do_losetup + exit 0 + ;; + -u|--uboot) + . "${PREFIX}"/do_flashuboot + exit 0 + ;; + --) shift + break + ;; + *) + echo "Not implemented: $1" >&2 + ;; + esac + shift +done + +# vim: set ft=sh ts=2 sw=2 sts=2 et diff --git a/telechips/scripts/do_crosscompile b/telechips/scripts/do_crosscompile new file mode 100755 index 0000000..40d8830 --- /dev/null +++ b/telechips/scripts/do_crosscompile @@ -0,0 +1,140 @@ +#!/bin/bash + +# Copyright (C) 2024 Steve Jeong +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see + +set -e + +# declare +declare -A CCList +CCList["arm"]="arm-linux-gnueabi-" +CCList["armhf"]="arm-linux-gnueabihf-" +CCList["arm64"]="aarch64-linux-gnu-" +CCList["x86"]="x86-64-linux-gnu-" + +help_msg() { + local msg="" + + case ${1} in + arch) + msg="e.g 'arm64' or 'x86' or ..." + ;; + config) + msg="e.g 'i386_defconfig' or 'oldconfig' or ..." + ;; + *) + ;; + esac + + echo "" + echo "[kernel ${1}]" + echo "${msg}" +} + +check_kernel_root() { + if [[ ! -d arch || ! -d init ]]; then + echo "Make sure you are currently in the path of the kernel root!" + exit 1 + else + ROOT=$(pwd -P) + fi +} + +request() { + local key="" + local params="" + + cd ${1} + while true; do + read -e -p "Input ${1}: " params + for param in ${params}; do + key=$(find ${ROOT}/${1} -name "${param/armhf/arm}" | wc -l) + if [[ ${key} -gt 0 || "x${param}" = "xoldconfig" ]]; then + continue + fi + key="invalid" + done + + [ "x${key}" != "xinvalid" ] && break + done + + cd ${ROOT} + + echo ${params} +} + +set_target() { + local option="" + local ret="" + + echo "" + echo "If it's your first build, you must do the build all.." + read -r -p "What do you wan't build? (all/dtbs/modules)? [A/d/m]: " option + case ${option} in + [dD][tT][bB][sS]|[dD]) + ret="dtbs" + ;; + [mM][oO][dD][uU][lL][eE][sS]|[mM]) + ret="modules" + ;; + *) + ret="all" + ;; + esac + + echo ${ret} +} + +main() { + local arch="" + local cc="" # cross-compiler + local config="" + local ret="" + local target="" + + # Verify that the current working path is the root of the kernel source. + check_kernel_root + + # config target's architecture + help_msg "arch" + ret=$(request "arch" | tail -n 1) + arch=${ret/armhf/arm} + cc=${CCList[${ret}]} + + # config target's configs + help_msg "config" + ret=$(request "arch/${arch}/configs" | tail -n 1) + config=${ret} + + target=$(set_target | tail -n 1) + export ARCH=${arch} + export CROSS_COMPILE=${cc} + if [[ ${config} == *"sub"* ]]; then + export KBUILD_OUTPUT=./build_sub + else + export KBUILD_OUTPUT=./build + fi + + # build + echo "make ARCH=${arch} ${config}" + make ${config} + echo "make ARCH=${arch} CROSS_COMPILE=${cc} ${target} -j$(nproc)" + make ${target} -j$(nproc) + ./mklinuxmtdimg_64bit.sh +} + +main + +# vim: ft=sh ts=2 sw=2 sts=2 et diff --git a/telechips/scripts/do_flashuboot b/telechips/scripts/do_flashuboot new file mode 100755 index 0000000..c88fd57 --- /dev/null +++ b/telechips/scripts/do_flashuboot @@ -0,0 +1,46 @@ +#!/bin/bash + +check_uboot_root() { + if [[ ! -d arch || ! -d board ]]; then + echo "" + exit 1 + else + ROOT=$(pwd -P) + fi +} + +main () { + check_uboot_root + cd ${ROOT} + + echo "build uboot for main-core" + . scripts/envsetup.sh << __EOF +1 +4 +1 +__EOF + +make tcc807x_defconfig telechips_mmc_boot.config +make -j12 + +sleep 3 + +} + +sub() { + check_uboot_root + cd ${ROOT} + + echo "build uboot for sub-core" + . scripts/envsetup.sh << __EOF +1 +4 +2 +__EOF + +make tcc807x_subcore_defconfig telechips_mmc_boot.config +make -j12 +} + +main +sub