├── .gitattributes ├── .gitignore ├── .gitmodules ├── Makefile ├── README.md ├── configure ├── rootfs └── debian-ubuntu │ └── etc │ ├── modprobe.d │ └── 8192cu.conf │ └── modules └── scripts ├── mk_android.sh ├── mk_ext4_rootfs.sh ├── mk_hwpack.sh ├── mk_livesuit_img.sh └── sunxi-media-create.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /chosen_board.mk 2 | /android/ 3 | /build/ 4 | /output/ 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "u-boot-sunxi"] 2 | path = u-boot-sunxi 3 | url = ../u-boot-sunxi.git 4 | [submodule "sunxi-tools"] 5 | path = sunxi-tools 6 | url = ../sunxi-tools.git 7 | [submodule "sunxi-boards"] 8 | path = sunxi-boards 9 | url = ../sunxi-boards.git 10 | [submodule "linux-sunxi"] 11 | path = linux-sunxi 12 | url = ../linux-sunxi.git 13 | [submodule "allwinner-tools"] 14 | path = allwinner-tools 15 | url = ../allwinner-tools.git 16 | [submodule "cedarx-libs"] 17 | path = cedarx-libs 18 | url = ../cedarx-libs.git 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean help 2 | .PHONY: tools u-boot linux libs hwpack hwpack-install 3 | .PHONY: linux-config livesuit android 4 | 5 | SUDO=sudo 6 | CROSS_COMPILE=arm-linux-gnueabihf- 7 | OUTPUT_DIR=$(CURDIR)/output 8 | BUILD_PATH=$(CURDIR)/build 9 | ROOTFS?=norootfs 10 | ROOTFS_BASENAME=$(basename $(basename $(ROOTFS))) 11 | Q= 12 | J=$(shell expr `grep ^processor /proc/cpuinfo | wc -l` \* 2) 13 | 14 | include chosen_board.mk 15 | 16 | HWPACK=$(OUTPUT_DIR)/$(BOARD)_hwpack.tar.xz 17 | U_O_PATH=$(BUILD_PATH)/$(UBOOT_CONFIG)-u-boot 18 | K_O_PATH=$(BUILD_PATH)/$(KERNEL_CONFIG)-linux 19 | U_CONFIG_H=$(U_O_PATH)/include/config.h 20 | K_DOT_CONFIG=$(K_O_PATH)/.config 21 | 22 | all: hwpack 23 | 24 | clean: 25 | rm -rf $(BUILD_PATH) 26 | rm -f chosen_board.mk 27 | 28 | ## tools 29 | tools: sunxi-tools/.git 30 | $(Q)$(MAKE) -C sunxi-tools 31 | 32 | ## u-boot 33 | $(U_CONFIG_H): u-boot-sunxi/.git 34 | $(Q)mkdir -p $(U_O_PATH) 35 | $(Q)$(MAKE) -C u-boot-sunxi $(UBOOT_CONFIG)_config O=$(U_O_PATH) CROSS_COMPILE=$(CROSS_COMPILE) -j$J 36 | 37 | u-boot: $(U_CONFIG_H) 38 | $(Q)$(MAKE) -C u-boot-sunxi all O=$(U_O_PATH) CROSS_COMPILE=$(CROSS_COMPILE) -j$J 39 | 40 | ## linux 41 | $(K_DOT_CONFIG): linux-sunxi/.git 42 | $(Q)mkdir -p $(K_O_PATH) 43 | $(Q)$(MAKE) -C linux-sunxi O=$(K_O_PATH) ARCH=arm $(KERNEL_CONFIG) 44 | 45 | linux: $(K_DOT_CONFIG) 46 | $(Q)$(MAKE) -C linux-sunxi O=$(K_O_PATH) ARCH=arm oldconfig 47 | $(Q)$(MAKE) -C linux-sunxi O=$(K_O_PATH) ARCH=arm CROSS_COMPILE=${CROSS_COMPILE} -j$J INSTALL_MOD_PATH=output uImage modules 48 | $(Q)$(MAKE) -C linux-sunxi O=$(K_O_PATH) ARCH=arm CROSS_COMPILE=${CROSS_COMPILE} -j$J INSTALL_MOD_PATH=output modules_install 49 | cd $(K_O_PATH) && ${CROSS_COMPILE}objcopy -R .note.gnu.build-id -S -O binary vmlinux bImage 50 | 51 | linux-config: $(K_DOT_CONFIG) 52 | $(Q)$(MAKE) -C linux-sunxi O=$(K_O_PATH) ARCH=arm menuconfig 53 | 54 | ## script.bin 55 | script.bin: tools 56 | $(Q)mkdir -p $(OUTPUT_DIR) 57 | $(Q)sunxi-tools/fex2bin sunxi-boards/sys_config/$(SOC)/$(BOARD).fex > $(BUILD_PATH)/$(BOARD).bin 58 | 59 | ## boot.scr 60 | boot.scr: 61 | $(Q)mkdir -p $(OUTPUT_DIR) 62 | $(Q)[ ! -s boot.cmd ] || mkimage -A arm -O u-boot -T script -C none -n "boot" -d boot.cmd $(BUILD_PATH)/boot.scr 63 | 64 | ## hwpack 65 | $(HWPACK): u-boot boot.scr script.bin linux libs 66 | $(Q)scripts/mk_hwpack.sh $@ 67 | 68 | hwpack: $(HWPACK) 69 | 70 | ## livesuit 71 | %.ext4: %.tar.gz 72 | $(Q)scripts/mk_ext4_rootfs.sh $< $@ 73 | 74 | livesuit: allwinner-tools/.git $(ROOTFS_BASENAME).ext4 tools linux 75 | $(Q)scripts/mk_livesuit_img.sh -R $(ROOTFS_BASENAME).ext4 76 | 77 | ## android 78 | android-%: 79 | $(Q)scripts/mk_android.sh $* 80 | 81 | android: android-build 82 | 83 | ## hwpack-install 84 | hwpack-install: $(HWPACK) 85 | $(Q)[ -s $(SD_CARD) ] || echo "Define SD_CARD variable" 86 | $(Q)$(SUDO) scripts/sunxi-media-create.sh $(SD_CARD) $(HWPACK) $(ROOTFS) 87 | 88 | libs: cedarx-libs/.git 89 | 90 | update: 91 | $(Q)git stash 92 | $(Q)git pull --rebase 93 | $(Q)git submodule -q init 94 | $(Q)git submodule -q foreach git stash save -q --include-untracked "make update stash" 95 | -$(Q)git submodule -q foreach git fetch -q 96 | -$(Q)git submodule -q foreach "git rebase origin HEAD || :" 97 | -$(Q)git submodule -q foreach "git stash pop -q || :" 98 | -$(Q)git stash pop -q 99 | $(Q)git submodule status 100 | 101 | %/.git: 102 | $(Q)git submodule init 103 | $(Q)git submodule update $* 104 | 105 | help: 106 | @echo "" 107 | @echo "Usage:" 108 | @echo " make hwpack - Default 'make'" 109 | @echo " make hwpack-install - Build and install hwpack and optional rootfs to sdcard" 110 | @echo " Arguments:" 111 | @echo " SD_CARD= - Target (ie. /dev/sdx)" 112 | @echo " ROOTFS= - Source rootfs (ie. rootfs.tar.gz)" 113 | @echo " make livesuit - Build and create livesuit image" 114 | @echo " Arguments:" 115 | @echo " ROOTFS= - Source rootfs (ie. rootfs.tar.gz)" 116 | @echo "" 117 | @echo " make android - **Experimental**" 118 | @echo " make clean" 119 | @echo " make update" 120 | @echo "" 121 | @echo "Optional targets:" 122 | @echo " make linux - Builds linux kernel" 123 | @echo " make linux-config - Menuconfig" 124 | @echo " make u-boot - Builds u-boot" 125 | @echo " make libs - Download libs" 126 | @echo " make tools - Builds open source tools" 127 | @echo "" 128 | 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sunxi-bsp 2 | ========= 3 | 4 | Getting Started 5 | --------------- 6 | 7 | 1. Choose a board doing `./configure my_board`, or `./configure` to see 8 | the list of supported ones. 9 | 10 | 2. Run 'make' to build hwpack or 'make help' to list available targets 11 | 12 | 13 | Overview 14 | -------- 15 | 16 | This repository provides various scripts to help hacking devices with Allwinner SOC. 17 | 18 | ./scripts/ 19 | a1x-initramfs.sh - Create initramfs inside target device 20 | mk_ext4_rootfs.sh - Ext4 rootfs from tar.gz 21 | mk_hwpack.sh - Helper script for Makefile 22 | mk_livesuit_img.sh - Android or Linux livesuit image 23 | sunxi-media-create.sh - Flash SD card from hwpack 24 | mk_android.sh - Helper script for Makefile 25 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | if [ ! -d sunxi-boards/sys_config/ ]; then 5 | git submodule init 6 | git submodule update sunxi-boards 7 | fi 8 | 9 | list_boards() { 10 | ls -1 sunxi-boards/sys_config/*/*.fex | 11 | sed -n -e 's|.*/\([^/]\+\)\.fex$|\1|p' | sort -V | 12 | sed -e 's|.*|\t* \0 \0-android|' 13 | } 14 | 15 | # keep the output `sh` friendly 16 | # i.e., no spaces around the '=' 17 | generate_board_mk() { 18 | local board="${1%-android}" android= soc= 19 | 20 | [ "$board" = "$1" ] || android=yes 21 | soc=$(ls -1 sunxi-boards/sys_config/*/$board.fex 2> /dev/null | cut -d/ -f3) 22 | 23 | cat <<-EOT 24 | BOARD=$board 25 | ANDROID=$android 26 | SOC=$soc 27 | UBOOT_CONFIG=$board 28 | EOT 29 | 30 | case "$soc" in 31 | a10) 32 | cat <<-EOT 33 | MACH=sun4i 34 | KERNEL_CONFIG=sun4i${android:+_crane}_defconfig 35 | EOT 36 | ;; 37 | a13) 38 | cat <<-EOT 39 | MACH=sun5i 40 | KERNEL_CONFIG=sun5i${android:+_nuclear}_defconfig 41 | EOT 42 | ;; 43 | a20) 44 | cat <<-EOT 45 | MACH=sun7i 46 | KERNEL_CONFIG=sun7i${android:+_wing}_defconfig 47 | EOT 48 | ;; 49 | *) 50 | echo "$soc: unsupported SoC" >&2 51 | return 1 52 | ;; 53 | esac 54 | } 55 | 56 | usage() { 57 | cat <<-EOT >&2 58 | Usage: $0 59 | 60 | supported boards: 61 | EOT 62 | list_boards 63 | } 64 | 65 | if [ $# -eq 0 ]; then 66 | usage 67 | elif ls -1 sunxi-boards/sys_config/*/${1%-android}.fex 2> /dev/null 1>&2; then 68 | out=chosen_board.mk 69 | if generate_board_mk "$1" > $out~; then 70 | mv $out~ $out 71 | echo "$1 configured. Now run \`make\`" 72 | else 73 | rm $out~ 74 | exit 1 75 | fi 76 | else 77 | echo "$1: invalid board name" >&2 78 | usage 79 | exit 1 80 | fi 81 | -------------------------------------------------------------------------------- /rootfs/debian-ubuntu/etc/modprobe.d/8192cu.conf: -------------------------------------------------------------------------------- 1 | # Workaround for dropping connections because power save 2 | options 8192cu rtw_power_mgnt=0 rtw_enusbss=0 3 | -------------------------------------------------------------------------------- /rootfs/debian-ubuntu/etc/modules: -------------------------------------------------------------------------------- 1 | # /etc/modules: kernel modules to load at boot time. 2 | # 3 | # This file contains the names of kernel modules that should be loaded 4 | # at boot time, one per line. Lines beginning with "#" are ignored. 5 | 6 | #For SATA Support 7 | sw_ahci_platform 8 | 9 | #Display and GPU 10 | lcd 11 | hdmi 12 | ump 13 | disp 14 | mali 15 | mali_drm 16 | 8192cu 17 | 18 | -------------------------------------------------------------------------------- /scripts/mk_android.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | die() { 4 | echo "$*" >&2 5 | exit 1 6 | } 7 | 8 | [ -s "./chosen_board.mk" ] || die "please run ./configure first." 9 | 10 | set -e 11 | 12 | . ./chosen_board.mk 13 | 14 | # Board-independent configuration variables 15 | REPO_TOOL_URL="https://dl-ssl.google.com/dl/googlesource/git-repo/repo" 16 | REPO_MANIFEST="git://github.com/CyanogenMod/android.git" 17 | REPO_LOCAL_MANIFEST="http://turl.linux-sunxi.org/local_manifest_jb.xml" 18 | REPO_BRANCH="jellybean" 19 | 20 | ANDROID_REPO_DIR="$PWD/android" 21 | PATH="$ANDROID_REPO_DIR:$PATH" 22 | ACTION="$1" 23 | 24 | if [ "$ACTION" != "sync" -a "$ACTION" != "clobber" -a "$ACTION" != "build" ]; then 25 | die "Invalid action specified" 26 | fi 27 | 28 | # Do we need to create the repo dir? 29 | if [ ! -d "$ANDROID_REPO_DIR" ]; then 30 | mkdir "$ANDROID_REPO_DIR" 31 | fi 32 | 33 | # Do we have the repo tool installed already? 34 | if [ ! -x "$ANDROID_REPO_DIR/repo" ]; then 35 | wget "$REPO_TOOL_URL" -O "$ANDROID_REPO_DIR/repo" || die "error downloading repo tool" 36 | chmod +x "$ANDROID_REPO_DIR/repo" 37 | fi 38 | 39 | cd "$ANDROID_REPO_DIR" 40 | 41 | # Update/download repo 42 | repo init -u "$REPO_MANIFEST" -b "$REPO_BRANCH" || die "error initializing repo" 43 | wget "$REPO_LOCAL_MANIFEST" -O "$ANDROID_REPO_DIR/.repo/local_manifest.xml" || die "error downloading local manifest" 44 | repo sync || die "error syncing repo" 45 | 46 | # And keep repo tool up to date 47 | cp "$ANDROID_REPO_DIR/.repo/repo/repo" "$ANDROID_REPO_DIR/repo" 48 | 49 | # Update the system: "make android-sync" 50 | if [ "$ACTION" = "sync" ]; then 51 | # We have already updated 52 | exit 0 53 | fi 54 | 55 | # Load android env commands 56 | . build/envsetup.sh 57 | 58 | # Clean the tree: "make android-clobber" 59 | if [ "$ACTION" = "clobber" ]; then 60 | mka clobber 61 | exit 0 62 | fi 63 | 64 | # Build Android: "make android" 65 | ./vendor/cm/get-prebuilts 66 | brunch "cm_$BOARD-userdebug" 67 | -------------------------------------------------------------------------------- /scripts/mk_ext4_rootfs.sh: -------------------------------------------------------------------------------- 1 | 2 | TARGET=$PWD"/target_tmp" 3 | 4 | cleanup() { 5 | sudo umount $TARGET || true 6 | sudo sudo rm -rf $TARGET 7 | } 8 | 9 | die() { 10 | echo "$*" >&2 11 | cleanup 12 | exit 1 13 | } 14 | 15 | set -e 16 | 17 | make_rootfs() 18 | { 19 | echo "Make rootfs" 20 | local rootfs=$(readlink -f "$1") 21 | local output=$(readlink -f "$2") 22 | local fsizeinbytes=$(gzip -lq "$rootfs" | awk -F" " '{print $2}') 23 | local fsizeMB=$(expr $fsizeinbytes / 1024 / 1024 + 200) 24 | local d= x= 25 | local rootfs_copied= 26 | 27 | echo "Make linux.ext4 (size="$fsizeMB")" 28 | mkdir -p $TARGET 29 | rm -f linux.ext4 30 | dd if=/dev/zero of=linux.ext4 bs=1M count="$fsizeMB" 31 | mkfs.ext4 linux.ext4 32 | sudo umount $TARGET || true 33 | sudo mount linux.ext4 $TARGET -o loop=/dev/loop0 34 | 35 | cd $TARGET 36 | echo "Unpacking $rootfs" 37 | sudo tar xzpf $rootfs || die "Unable to extract rootfs" 38 | 39 | for x in '' \ 40 | 'binary/boot/filesystem.dir' 'binary'; do 41 | 42 | d="$TARGET${x:+/$x}" 43 | 44 | if [ -d "$d/sbin" ]; then 45 | rootfs_copied=1 46 | sudo mv "$d"/* $TARGET || 47 | die "Failed to copy rootfs data" 48 | break 49 | fi 50 | done 51 | 52 | [ -n "$rootfs_copied" ] || die "Unsupported rootfs" 53 | 54 | cd - > /dev/null 55 | 56 | mv linux.ext4 $output 57 | } 58 | 59 | [ $# -eq 2 ] || die "Usage: $0 [rootfs.tar.gz] [output]" 60 | 61 | make_rootfs "$1" "$2" 62 | cleanup 63 | 64 | -------------------------------------------------------------------------------- /scripts/mk_hwpack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | die() { 4 | echo "$*" >&2 5 | exit 1 6 | } 7 | 8 | [ -s "./chosen_board.mk" ] || die "please run ./configure first." 9 | 10 | set -e 11 | 12 | . ./chosen_board.mk 13 | 14 | U_O_PATH="build/$UBOOT_CONFIG-u-boot" 15 | K_O_PATH="build/$KERNEL_CONFIG-linux" 16 | HWPACK_DIR="build/${BOARD}_hwpack" 17 | 18 | ABI=armhf 19 | 20 | cp_debian_files() { 21 | local rootfs="$1" 22 | local cedarxdir="cedarx-libs/libcedarv/linux-$ABI" 23 | local libtype="x11" # or framebuffer 24 | local x= y= 25 | 26 | echo "Debian/Ubuntu hwpack" 27 | cp -r "rootfs/debian-ubuntu"/* "$rootfs/" 28 | 29 | ## libs 30 | install -m 0755 $(find "$cedarxdir" -name '*.so') "$rootfs/lib/" 31 | 32 | ## kernel modules 33 | cp -r "$K_O_PATH/output/lib/modules" "$rootfs/lib/" 34 | rm -f "$rootfs/lib/modules"/*/source 35 | rm -f "$rootfs/lib/modules"/*/build 36 | 37 | ## bins 38 | #cp ../../a10-tools/a1x-initramfs.sh ${OUTPUT_DIR}/${BOARD}_hwpack/rootfs/usr/bin 39 | #chmod 755 ${OUTPUT_DIR}/${BOARD}_hwpack/rootfs/usr/bin/a1x-initramfs.sh 40 | } 41 | 42 | cp_android_files() { 43 | local rootfs="$1" f= 44 | 45 | echo "Android hwpack" 46 | 47 | mkdir -p "${rootfs}/boot" 48 | ## kernel 49 | cp -r "$K_O_PATH"/arch/arm/boot/uImage "${rootfs}/boot/" 50 | cp -r "build/$BOARD.bin" "${rootfs}/boot/script.bin" 51 | 52 | ## kernel modules 53 | mkdir -p "$rootfs/system/lib/modules" 54 | find "$K_O_PATH/output/lib/modules" -name "*.ko" -print0 |xargs -0 cp -t "$rootfs/system/lib/modules/" 55 | 56 | ## boot scripts (optional) 57 | for f in boot.scr uEnv.txt; do 58 | if [ -s "build/$f" ]; then 59 | cp "build/$f" "$rootfs/boot/" 60 | fi 61 | done 62 | } 63 | 64 | create_hwpack() { 65 | local hwpack="$1" 66 | local rootfs="$HWPACK_DIR/rootfs" 67 | local kerneldir="$HWPACK_DIR/kernel" 68 | local bootloader="$HWPACK_DIR/bootloader" 69 | local f= 70 | 71 | rm -rf "$HWPACK_DIR" 72 | 73 | mkdir -p "$rootfs/usr/bin" "$rootfs/lib" 74 | 75 | if [ -z "$ANDROID" ]; then 76 | cp_debian_files "$rootfs" 77 | else 78 | cp_android_files "$rootfs" 79 | fi 80 | 81 | ## kernel 82 | mkdir -p "$kerneldir" 83 | cp -r "$K_O_PATH"/arch/arm/boot/uImage "$kerneldir/" 84 | cp -r "build/$BOARD.bin" "$kerneldir/script.bin" 85 | 86 | ## boot scripts (optional) 87 | for f in boot.scr uEnv.txt; do 88 | if [ -s "build/$f" ]; then 89 | cp "build/$f" "$kerneldir/" 90 | fi 91 | done 92 | 93 | ## bootloader 94 | mkdir -p "$bootloader" 95 | cp -r "$U_O_PATH/u-boot-sunxi-with-spl.bin" "$bootloader/" 96 | cp -r "$U_O_PATH/spl/sunxi-spl.bin" "$bootloader/" 97 | cp -r "$U_O_PATH/u-boot.bin" "$bootloader/" 98 | cp -r "$U_O_PATH/u-boot.img" "$bootloader/" 99 | 100 | ## compress hwpack 101 | cd "$HWPACK_DIR" 102 | case "$hwpack" in 103 | *.7z) 104 | 7z u -up1q0r2x1y2z1w2 -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on "$hwpack" . 105 | ;; 106 | *.tar.bz2) 107 | find . ! -type d | cut -c3- | sort -V | tar -jcf "$hwpack" -T - 108 | ;; 109 | *.tar.xz) 110 | find . ! -type d | cut -c3- | sort -V | tar -Jcf "$hwpack" -T - 111 | ;; 112 | *) 113 | die "Not supported hwpack format" 114 | ;; 115 | esac 116 | cd - > /dev/null 117 | echo "Done." 118 | } 119 | 120 | [ $# -eq 1 ] || die "Usage: $0 " 121 | 122 | create_hwpack "$1" 123 | -------------------------------------------------------------------------------- /scripts/mk_livesuit_img.sh: -------------------------------------------------------------------------------- 1 | die() { 2 | echo "$*" >&2 3 | exit 1 4 | } 5 | 6 | [ -s "./chosen_board.mk" ] || die "please run ./configure first." 7 | 8 | set -e 9 | 10 | . ./chosen_board.mk 11 | 12 | DRAGON=${PWD}/allwinner-tools/dragon/dragon 13 | FSBUILD=${PWD}/allwinner-tools/fsbuild/fsbuild 14 | BINS=${PWD}/allwinner-tools/bins 15 | LIVESUIT_DIR=${PWD}/allwinner-tools/livesuit 16 | SOURCE_DIR=${LIVESUIT_DIR}/${SOC} 17 | BUILD_DIR=${PWD}/build/${BOARD}_livesuit 18 | BUILD_DIR_LOCAL=build/${BOARD}_livesuit 19 | SUNXI_TOOLS=${PWD}/sunxi-tools 20 | ROOTFS= 21 | RECOVERY= 22 | BOOT= 23 | SYSTEM= 24 | ANDROID=true 25 | 26 | show_usage_and_die() 27 | { 28 | echo "Usage (linux): $0 -R [rootfs.tar.gz]" 29 | echo "Usage (android): $0 -b [boot.img] -s [system.img] -r [recovery.img]" 30 | exit 1 31 | } 32 | 33 | modify_image_cfg() 34 | { 35 | echo "Modifying image.cfg: $1" 36 | cp -rf $1 ${BUILD_DIR}/image.cfg 37 | sed -i -e "s|^INPUT_DIR..*$|INPUT_DIR=${BUILD_DIR}|g" \ 38 | -e "s|^EFEX_DIR..*$|EFEX_DIR=${SOURCE_DIR}/eFex|g" \ 39 | -e "s|^imagename..*$|imagename=output/${BOARD}_livesuit.img|g" \ 40 | ${BUILD_DIR}/image.cfg 41 | } 42 | 43 | 44 | 45 | do_addchecksum() 46 | { 47 | echo "Add checksum" 48 | # checksum for all fex (for android) 49 | ${BINS}/FileAddSum ${BUILD_DIR}/bootloader.fex ${BUILD_DIR}/vbootloader.fex 50 | ${BINS}/FileAddSum ${BUILD_DIR}/env.fex ${BUILD_DIR}/venv.fex 51 | ${BINS}/FileAddSum ${BUILD_DIR}/boot.fex ${BUILD_DIR}/vboot.fex 52 | ${BINS}/FileAddSum ${BUILD_DIR}/system.fex ${BUILD_DIR}/vsystem.fex 53 | ${BINS}/FileAddSum ${BUILD_DIR}/recovery.fex ${BUILD_DIR}/vrecovery.fex 54 | } 55 | 56 | make_bootfs() 57 | { 58 | echo "Make bootfs: $1" 59 | cp -rf ${SOURCE_DIR}/eFex/split_xxxx.fex ${BUILD_DIR} 60 | cp -rf ${SOURCE_DIR}/eFex/card/mbr.fex ${BUILD_DIR} 61 | cp -rf ${SOURCE_DIR}/wboot/bootfs ${BUILD_DIR} 62 | cp -rf ${SOURCE_DIR}/wboot/bootfs.ini ${BUILD_DIR} 63 | cp -rf ${SOURCE_DIR}/wboot/diskfs.fex ${BUILD_DIR} 64 | 65 | sed -i -e "s|^fsname=..*$|fsname=${BUILD_DIR}/bootloader.fex|g" \ 66 | -e "s|^root0=..*$|root0=${BUILD_DIR}/bootfs|g" ${BUILD_DIR}/bootfs.ini 67 | 68 | # get env.fex 69 | ${BINS}/u_boot_env_gen $1 ${BUILD_DIR}/env.fex 70 | 71 | # u-boot 72 | ${SUNXI_TOOLS}/fex2bin ${BUILD_DIR}/sys_config1.fex > ${BUILD_DIR}/bootfs/script0.bin 73 | ${SUNXI_TOOLS}/fex2bin ${BUILD_DIR}/sys_config1.fex > ${BUILD_DIR}/bootfs/script.bin 74 | 75 | # other 76 | mkdir -pv ${BUILD_DIR}/bootfs/vendor/system/media 77 | echo "empty" > ${BUILD_DIR}/bootfs/vendor/system/media/vendor 78 | 79 | if [ $ANDROID = false ]; then 80 | echo "Copying linux kernel and modules" 81 | cp ./build/${KERNEL_CONFIG}-linux/arch/arm/boot/uImage ${BUILD_DIR}/bootfs/ 82 | mkdir -pv ${BUILD_DIR}/bootfs/lib/modules 83 | cp -a ./build/${KERNEL_CONFIG}-linux/output/lib/modules ${BUILD_DIR}/bootfs/lib 84 | rm -f ${BUILD_DIR}/bootfs/lib/modules/*/source 85 | rm -f ${BUILD_DIR}/bootfs/lib/modules/*/build 86 | fi 87 | 88 | # build 89 | ${BINS}/update_mbr ${BUILD_DIR}/sys_config.bin ${BUILD_DIR}/mbr.fex 4 16777216 90 | ${FSBUILD} ${BUILD_DIR}/bootfs.ini ${BUILD_DIR}/split_xxxx.fex 91 | } 92 | 93 | make_boot0_boot1() 94 | { 95 | echo "Make boot0 boot1" 96 | cp -rf ${SOURCE_DIR}/eGon/storage_media/nand/boot0.bin ${BUILD_DIR} 97 | cp -rf ${SOURCE_DIR}/eGon/storage_media/nand/boot1.bin ${BUILD_DIR} 98 | cp -rf ${SOURCE_DIR}/eGon/storage_media/sdcard/boot0.bin ${BUILD_DIR}/card_boot0.fex 99 | cp -rf ${SOURCE_DIR}/eGon/storage_media/sdcard/boot1.bin ${BUILD_DIR}/card_boot1.fex 100 | 101 | ${BINS}/update_23 ${BUILD_DIR_LOCAL}/sys_config1.bin ${BUILD_DIR_LOCAL}/boot0.bin ${BUILD_DIR_LOCAL}/boot1.bin 102 | ${BINS}/update_23 ${BUILD_DIR_LOCAL}/sys_config1.bin ${BUILD_DIR_LOCAL}/card_boot0.fex ${BUILD_DIR_LOCAL}/card_boot1.fex SDMMC_CARD 103 | } 104 | 105 | make_sys_configs() 106 | { 107 | echo "Make sys configs: $1" 108 | cp $1 ${BUILD_DIR}/sys_config.fex 109 | ${BINS}/script ${BUILD_DIR}/sys_config.fex 110 | 111 | cp sunxi-boards/sys_config/${SOC}/${BOARD}.fex ${BUILD_DIR}/sys_config1.fex 112 | ${SUNXI_TOOLS}/fex2bin ${BUILD_DIR}/sys_config1.fex > ${BUILD_DIR}/sys_config1.bin 113 | 114 | } 115 | 116 | cp_android_files() 117 | { 118 | ln -svf $RECOVERY ${BUILD_DIR}/recovery.fex 119 | ln -svf $BOOT ${BUILD_DIR}/boot.fex 120 | ln -svf $SYSTEM ${BUILD_DIR}/system.fex 121 | 122 | } 123 | 124 | do_pack() 125 | { 126 | echo "!!!Packing!!!\n" 127 | 128 | # if [ $PACK_CHIP = sun4i ]; then 129 | # if [ $PACK_DEBUG = card0 ]; then 130 | # cp $TOOLS_DIR/awk_debug_card0 out/awk_debug_card0 131 | # TX=`awk '$0~"a10"{print $2}' pctools/linux/card_debug_pin` 132 | # RX=`awk '$0~"a10"{print $3}' pctools/linux/card_debug_pin` 133 | # sed -i s'/uart_debug_tx =/uart_debug_tx = '$TX'/g' out/awk_debug_card0 134 | # sed -i s'/uart_debug_rx =/uart_debug_rx = '$RX'/g' out/awk_debug_card0 135 | # sed -i s'/uart_tx =/uart_tx = '$TX'/g' out/awk_debug_card0 136 | # sed -i s'/uart_rx =/uart_rx = '$RX'/g' out/awk_debug_card0 137 | # awk -f out/awk_debug_card0 out/sys_config1.fex > out/a.fex 138 | # rm out/sys_config1.fex 139 | # mv out/a.fex out/sys_config1.fex 140 | # echo "uart -> card0 !!!" 141 | # fi 142 | # fi 143 | mkdir -p ${BUILD_DIR} 144 | if [ $ANDROID = true ]; then 145 | make_sys_configs ${LIVESUIT_DIR}/default/sys_config_android.fex 146 | make_boot0_boot1 147 | make_bootfs ${LIVESUIT_DIR}/default/env_android.cfg 148 | modify_image_cfg ${LIVESUIT_DIR}/default/image_android.cfg 149 | cp_android_files 150 | do_addchecksum 151 | else 152 | make_sys_configs ${LIVESUIT_DIR}/default/sys_config_linux.fex 153 | make_boot0_boot1 154 | make_bootfs ${LIVESUIT_DIR}/default/env_linux.cfg 155 | ln -svf "$ROOTFS" ${BUILD_DIR}/rootfs.fex 156 | modify_image_cfg ${LIVESUIT_DIR}/default/image_linux.cfg 157 | fi 158 | mkdir -pv output 159 | echo "Generating image" 160 | ${DRAGON} ${BUILD_DIR}/image.cfg 161 | rm -rf ${BUILD_DIR} 162 | echo "Done" 163 | } 164 | 165 | while getopts R:r:b:s: opt; do 166 | case "$opt" in 167 | R) ROOTFS=$(readlink -f "$OPTARG"); ANDROID=false ;; 168 | r) RECOVERY=$(readlink -f "$OPTARG") ;; 169 | b) BOOT=$(readlink -f "$OPTARG") ;; 170 | s) SYSTEM=$(readlink -f "$OPTARG") ;; 171 | :) show_usage_and_die ;; 172 | *) show_usage_and_die ;; 173 | esac 174 | done 175 | 176 | if [ $ANDROID = true ]; then 177 | [ -e "$RECOVERY" ] || show_usage_and_die 178 | [ -e "$BOOT" ] || show_usage_and_die 179 | [ -e "$SYSTEM" ] || show_usage_and_die 180 | else 181 | [ -e "$ROOTFS" ] || show_usage_and_die 182 | fi 183 | 184 | do_pack 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /scripts/sunxi-media-create.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Usage ./sunxi-media-create.sh /dev/sdx hwpack rootfs 3 | 4 | hwpack_update_only=0 5 | 6 | BOOT_SIZE=64 7 | 8 | TEMP="${TMPDIR:-/tmp}/.sunxi-media-create.$$" 9 | HWPACKDIR="$TEMP/hwpack" 10 | ROOTFSDIR="$TEMP/rootfs" 11 | MNTBOOT="$TEMP/mnt_boot" 12 | MNTROOT="$TEMP/mnt_root" 13 | 14 | cleanup() { 15 | local x= 16 | # umount card 17 | for x in $MNTBOOT $MNTROOT; do 18 | x=$(readlink -f "$x") 19 | if grep -q " $x " /proc/mounts; then 20 | umount "$x" || exit 1 21 | fi 22 | done 23 | 24 | # and delete temporal files 25 | rm -rf --one-file-system "$TEMP" 26 | } 27 | 28 | die() { 29 | echo "$*" >&2 30 | cleanup 31 | exit 1 32 | } 33 | 34 | title() { 35 | echo 36 | echo "===" 37 | echo "=== $* ===" 38 | echo "===" 39 | } 40 | 41 | checkSyntax () { 42 | if [ $# -lt 3 ]; then 43 | echo "Usage: $0 [device] [hwpack] [rootfs]" 44 | echo "Write norootfs for [rootfs] if you want to only update" 45 | echo "u-boot, script.bin, the kernel and modules" 46 | exit 1 47 | fi 48 | 49 | [ -b "$1" ] || die "$1: Invalid device" 50 | [ -s "$2" ] || die "$2: Hardware pack not found" 51 | 52 | if [ "$3" = norootfs ]; then 53 | hwpack_update_only=1; 54 | elif [ ! -s "$3" ]; then 55 | die "$3: rootfs file not found" 56 | fi 57 | } 58 | 59 | umountSD () { 60 | local partlist=$(grep "^$1" /proc/mounts | cut -d' ' -f1) 61 | [ -z "$partlist" ] || umount $partlist 62 | } 63 | 64 | partitionSD () { 65 | local dev="$1" subdevice= 66 | local x= 67 | case "$dev" in 68 | */mmcblk*|*/loop*) 69 | subdevice="${1}p" 70 | ;; 71 | *) 72 | subdevice="$1" 73 | ;; 74 | esac 75 | 76 | title "Partitioning $dev" 77 | dd if=/dev/zero of="$dev" bs=1M count=1 || 78 | die "$dev: failed to zero the first MB" 79 | 80 | x=$(expr $BOOT_SIZE \* 2048) 81 | sfdisk --in-order -L -uS "$dev" <<-EOT 82 | 2048,$x,c 83 | ,,L 84 | EOT 85 | [ $? -eq 0 ] || 86 | die "$dev: failed to repartition media" 87 | 88 | sleep 1 89 | sfdisk -L -R "$dev" || 90 | die "$dev: failed to reload media" 91 | 92 | title "Format Partition 1 to VFAT" 93 | mkfs.vfat -I ${subdevice}1 || 94 | die "${subdevice}1: failed to format partition" 95 | 96 | title "Format Partition 2 to EXT4" 97 | mkfs.ext4 ${subdevice}2 || 98 | die "${subdevice}2: failed to format partition" 99 | } 100 | 101 | extract() { 102 | local f=$(readlink -f "$1") 103 | title "Extracting $3" 104 | 105 | mkdir -p "$2" 106 | cd "$2" 107 | case "$f" in 108 | *.tar.bz2|*.tbz2) 109 | tar xjpf "$f" 110 | ;; 111 | *.tar.gz|*.tgz) 112 | tar xzpf "$f" 113 | ;; 114 | *.7z|*.lzma) 115 | 7z x "$f" 116 | ;; 117 | *.tar.xz) 118 | tar xJpf "$f" 119 | ;; 120 | *) 121 | die "$f: unknown file extension" 122 | ;; 123 | esac 124 | cd - > /dev/null 125 | } 126 | 127 | copyUbootSpl () 128 | { 129 | dd if=$2 bs=1024 of=$1 seek=8 130 | } 131 | 132 | copyUboot () 133 | { 134 | dd if=$2 bs=1024 of=$1 seek=40 135 | } 136 | 137 | mountPartitions () 138 | { 139 | local dev="$1" subdevice= 140 | case "$dev" in 141 | */mmcblk*|*/loop*) 142 | subdevice="${1}p" 143 | ;; 144 | *) 145 | subdevice="$1" 146 | ;; 147 | esac 148 | 149 | mkdir -p "$MNTROOT" "$MNTBOOT" || 150 | die "Failed to create SD card mount points" 151 | 152 | mount ${subdevice}1 "$MNTBOOT" || 153 | die "Failed to mount VFAT partition (SD)" 154 | 155 | mount ${subdevice}2 "$MNTROOT" || 156 | die "Failed to mount EXT4 partition (SD)" 157 | } 158 | 159 | copyData () 160 | { 161 | local d= x= 162 | local rootfs_copied= 163 | 164 | echo "Copy VFAT partition files to SD Card" 165 | cp $HWPACKDIR/kernel/uImage $MNTBOOT || 166 | die "Failed to copy VFAT partition data to SD Card" 167 | cp $HWPACKDIR/kernel/*.bin $MNTBOOT/script.bin || 168 | die "Failed to copy VFAT partition data to SD Card" 169 | if [ -s $HWPACKDIR/kernel/*.scr ]; then 170 | cp $HWPACKDIR/kernel/*.scr $MNTBOOT/boot.scr || 171 | die "Failed to copy VFAT partition data to SD Card" 172 | fi 173 | 174 | if [ ${hwpack_update_only} -eq 0 ]; then 175 | title "Copy rootfs partition files to SD Card" 176 | for x in '' \ 177 | 'binary/boot/filesystem.dir' 'binary'; do 178 | 179 | d="$ROOTFSDIR${x:+/$x}" 180 | 181 | if [ -d "$d/sbin" ]; then 182 | rootfs_copied=1 183 | cp -a "$d"/* "$MNTROOT" || 184 | die "Failed to copy rootfs partition data to SD Card" 185 | break 186 | fi 187 | done 188 | 189 | [ -n "$rootfs_copied" ] || die "Unsupported rootfs" 190 | fi 191 | 192 | title "Copy hwpack rootfs files" 193 | # Fedora uses a softlink for lib. Adjust, if needed. 194 | if [ -L $MNTROOT/lib ]; then 195 | # Find where it points. For Fedora, we expect usr/lib. 196 | DEST=`/bin/ls -l $MNTROOT/lib | sed -e 's,.* ,,'` 197 | if [ "$DEST" = "usr/lib" ]; then 198 | d="$HWPACKDIR/rootfs" 199 | if [ -d "$d/lib" ]; then 200 | mkdir -p "$d/usr/lib/" 201 | mv "$d/lib"/* "$d/usr/lib/" 202 | rmdir "$d/lib" 203 | fi 204 | fi 205 | fi 206 | cp -a $HWPACKDIR/rootfs/* $MNTROOT/ || 207 | die "Failed to copy rootfs hwpack files to SD Card" 208 | } 209 | 210 | # "main" 211 | checkSyntax $1 $2 $3 212 | umountSD $1 213 | if [ ${hwpack_update_only} -eq 0 ]; then 214 | partitionSD $1 215 | fi 216 | 217 | extract $2 $HWPACKDIR/ "HW Pack" 218 | if [ ${hwpack_update_only} -eq 0 ]; then 219 | extract $3 $ROOTFSDIR/ "RootFS" 220 | fi 221 | 222 | title "Copy U-Boot/SPL to SD Card" 223 | copyUbootSpl $1 $HWPACKDIR/bootloader/sunxi-spl.bin 224 | copyUboot $1 $HWPACKDIR/bootloader/u-boot.img 225 | mountPartitions $1 226 | copyData 227 | cleanup 228 | 229 | echo "Done." 230 | --------------------------------------------------------------------------------