10f66f451Sopenharmony_ci#!/bin/bash
20f66f451Sopenharmony_ci
30f66f451Sopenharmony_ci# Clear environment variables by restarting script w/bare minimum passed through
40f66f451Sopenharmony_ci[ -z "$NOCLEAR" ] &&
50f66f451Sopenharmony_ci  exec env -i NOCLEAR=1 HOME="$HOME" PATH="$PATH" LINUX="$LINUX" \
60f66f451Sopenharmony_ci    CROSS_COMPILE="$CROSS_COMPILE" CROSS_SHORT="$CROSS_SHORT" "$0" "$@"
70f66f451Sopenharmony_ci
80f66f451Sopenharmony_ci# assign command line NAME=VALUE args to env vars
90f66f451Sopenharmony_ciwhile [ $# -ne 0 ]
100f66f451Sopenharmony_cido
110f66f451Sopenharmony_ci  X="${1/=*/}"
120f66f451Sopenharmony_ci  Y="${1#*=}"
130f66f451Sopenharmony_ci  [ "${1/=/}" != "$1" ] && eval "export $X=\"\$Y\"" || echo "unknown $i"
140f66f451Sopenharmony_ci  shift
150f66f451Sopenharmony_cidone
160f66f451Sopenharmony_ci
170f66f451Sopenharmony_ci# If we're cross compiling, set appropriate environment variables.
180f66f451Sopenharmony_ciif [ -z "$CROSS_COMPILE" ]
190f66f451Sopenharmony_cithen
200f66f451Sopenharmony_ci  echo "Building natively"
210f66f451Sopenharmony_ci  if ! cc --static -xc - -o /dev/null <<< "int main(void) {return 0;}"
220f66f451Sopenharmony_ci  then
230f66f451Sopenharmony_ci    echo "Warning: host compiler can't create static binaries." >&2
240f66f451Sopenharmony_ci    sleep 3
250f66f451Sopenharmony_ci  fi
260f66f451Sopenharmony_cielse
270f66f451Sopenharmony_ci  CROSS_PATH="$(dirname "$(which "${CROSS_COMPILE}cc")")"
280f66f451Sopenharmony_ci  CROSS_BASE="$(basename "$CROSS_COMPILE")"
290f66f451Sopenharmony_ci  [ -z "$CROSS_SHORT" ] && CROSS_SHORT="${CROSS_BASE/-*/}"
300f66f451Sopenharmony_ci  echo "Cross compiling to $CROSS_SHORT"
310f66f451Sopenharmony_ci  if [ -z "$CROSS_PATH" ]
320f66f451Sopenharmony_ci  then
330f66f451Sopenharmony_ci    echo "no ${CROSS_COMPILE}cc in path" >&2
340f66f451Sopenharmony_ci    exit 1
350f66f451Sopenharmony_ci  fi
360f66f451Sopenharmony_cifi
370f66f451Sopenharmony_ci
380f66f451Sopenharmony_ci# set up directories (can override most of these paths on cmdline)
390f66f451Sopenharmony_ciTOP="$PWD/root"
400f66f451Sopenharmony_ci[ -z "$BUILD" ] && BUILD="$TOP/build"
410f66f451Sopenharmony_ci[ -z "$AIRLOCK" ] && AIRLOCK="$TOP/airlock"
420f66f451Sopenharmony_ci[ -z "$OUTPUT" ] && OUTPUT="$TOP/${CROSS_SHORT:-host}"
430f66f451Sopenharmony_ci[ -z "$ROOT" ] && ROOT="$OUTPUT/${CROSS_BASE}fs" && rm -rf "$ROOT"
440f66f451Sopenharmony_ciMYBUILD="$BUILD/${CROSS_BASE:-host-}tmp"
450f66f451Sopenharmony_cirm -rf "$MYBUILD" && mkdir -p "$MYBUILD" || exit 1
460f66f451Sopenharmony_ci
470f66f451Sopenharmony_ci# Stabilize cross compiling by providing known $PATH contents
480f66f451Sopenharmony_ciif [ ! -z "$CROSS_COMPILE" ]
490f66f451Sopenharmony_cithen
500f66f451Sopenharmony_ci  if [ ! -e "$AIRLOCK/toybox" ]
510f66f451Sopenharmony_ci  then
520f66f451Sopenharmony_ci    echo === Create airlock dir
530f66f451Sopenharmony_ci
540f66f451Sopenharmony_ci    PREFIX="$AIRLOCK" KCONFIG_CONFIG="$TOP"/.airlock CROSS_COMPILE= \
550f66f451Sopenharmony_ci      make clean defconfig toybox install_airlock &&
560f66f451Sopenharmony_ci    rm "$TOP"/.airlock || exit 1
570f66f451Sopenharmony_ci  fi
580f66f451Sopenharmony_ci  export PATH="$CROSS_PATH:$AIRLOCK"
590f66f451Sopenharmony_cifi
600f66f451Sopenharmony_ci
610f66f451Sopenharmony_ci### Create files and directories
620f66f451Sopenharmony_cimkdir -p "$ROOT"/{etc,tmp,proc,sys,dev,home,mnt,root,usr/{bin,sbin,lib},var} &&
630f66f451Sopenharmony_cichmod a+rwxt "$ROOT"/tmp && ln -s usr/{bin,sbin,lib} "$ROOT" || exit 1
640f66f451Sopenharmony_ci
650f66f451Sopenharmony_ci# init script. Runs as pid 1 from initramfs to set up and hand off system.
660f66f451Sopenharmony_cicat > "$ROOT"/init << 'EOF' &&
670f66f451Sopenharmony_ci#!/bin/sh
680f66f451Sopenharmony_ci
690f66f451Sopenharmony_ciexport HOME=/home
700f66f451Sopenharmony_ciexport PATH=/bin:/sbin
710f66f451Sopenharmony_ci
720f66f451Sopenharmony_cimountpoint -q proc || mount -t proc proc proc
730f66f451Sopenharmony_cimountpoint -q sys || mount -t sysfs sys sys
740f66f451Sopenharmony_ciif ! mountpoint -q dev
750f66f451Sopenharmony_cithen
760f66f451Sopenharmony_ci  mount -t devtmpfs dev dev || mdev -s
770f66f451Sopenharmony_ci  mkdir -p dev/pts
780f66f451Sopenharmony_ci  mountpoint -q dev/pts || mount -t devpts dev/pts dev/pts
790f66f451Sopenharmony_cifi
800f66f451Sopenharmony_ci
810f66f451Sopenharmony_ciif [ $$ -eq 1 ]
820f66f451Sopenharmony_cithen
830f66f451Sopenharmony_ci  # Setup networking for QEMU (needs /proc)
840f66f451Sopenharmony_ci  ifconfig eth0 10.0.2.15
850f66f451Sopenharmony_ci  route add default gw 10.0.2.2
860f66f451Sopenharmony_ci  [ "$(date +%s)" -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov
870f66f451Sopenharmony_ci  [ "$(date +%s)" -lt 10000000 ] && ntpd -nq -p north-america.pool.ntp.org
880f66f451Sopenharmony_ci
890f66f451Sopenharmony_ci  [ -z "$CONSOLE" ] &&
900f66f451Sopenharmony_ci    CONSOLE="$(sed -n 's@.* console=\(/dev/\)*\([^ ]*\).*@\2@p' /proc/cmdline)"
910f66f451Sopenharmony_ci
920f66f451Sopenharmony_ci  [ -z "$HANDOFF" ] && HANDOFF=/bin/sh && echo Type exit when done.
930f66f451Sopenharmony_ci  [ -z "$CONSOLE" ] && CONSOLE=console
940f66f451Sopenharmony_ci  exec /sbin/oneit -c /dev/"$CONSOLE" $HANDOFF
950f66f451Sopenharmony_cielse
960f66f451Sopenharmony_ci  /bin/sh
970f66f451Sopenharmony_ci  umount /dev/pts /dev /sys /proc
980f66f451Sopenharmony_cifi
990f66f451Sopenharmony_ciEOF
1000f66f451Sopenharmony_cichmod +x "$ROOT"/init &&
1010f66f451Sopenharmony_ci
1020f66f451Sopenharmony_ci# /etc/passwd with both kernel special accounts (root and nobody) + guest user
1030f66f451Sopenharmony_cicat > "$ROOT"/etc/passwd << 'EOF' &&
1040f66f451Sopenharmony_ciroot::0:0:root:/home/root:/bin/sh
1050f66f451Sopenharmony_ciguest:x:500:500:guest:/home/guest:/bin/sh
1060f66f451Sopenharmony_cinobody:x:65534:65534:nobody:/proc/self:/dev/null
1070f66f451Sopenharmony_ciEOF
1080f66f451Sopenharmony_ci
1090f66f451Sopenharmony_ci# /etc/group with groups corresponding to each /etc/passwd user
1100f66f451Sopenharmony_cicat > "$ROOT"/etc/group << 'EOF' &&
1110f66f451Sopenharmony_ciroot:x:0:
1120f66f451Sopenharmony_ciguest:x:500:
1130f66f451Sopenharmony_cinobody:x:65534:
1140f66f451Sopenharmony_ciEOF
1150f66f451Sopenharmony_ci
1160f66f451Sopenharmony_ci# /etc/resolv.conf using Google's public nameserver. (We could use QEMU's
1170f66f451Sopenharmony_ci# 10.0.2.2 forwarder here, but this way works in both chroot and QEMU.)
1180f66f451Sopenharmony_ciecho "nameserver 8.8.8.8" > "$ROOT"/etc/resolv.conf || exit 1
1190f66f451Sopenharmony_ci
1200f66f451Sopenharmony_ci# Build toybox
1210f66f451Sopenharmony_ci
1220f66f451Sopenharmony_cimake clean
1230f66f451Sopenharmony_ciif [ -z .config ]
1240f66f451Sopenharmony_cithen
1250f66f451Sopenharmony_ci  make defconfig
1260f66f451Sopenharmony_ci  # Work around musl-libc design flaw.
1270f66f451Sopenharmony_ci  [ "${CROSS_BASE/fdpic//}" != "$CROSS_BASE" ] &&
1280f66f451Sopenharmony_ci    sed -i 's/.*\(CONFIG_TOYBOX_MUSL_NOMMU_IS_BROKEN\).*/\1=y/' .config
1290f66f451Sopenharmony_cielse
1300f66f451Sopenharmony_ci  make silentoldconfig
1310f66f451Sopenharmony_cifi
1320f66f451Sopenharmony_ciLDFLAGS=--static PREFIX="$ROOT" make toybox install || exit 1
1330f66f451Sopenharmony_ci
1340f66f451Sopenharmony_ci# Abort early if no kernel source specified
1350f66f451Sopenharmony_ciif [ -z "$LINUX" ] || [ ! -d "$LINUX/kernel" ]
1360f66f451Sopenharmony_cithen
1370f66f451Sopenharmony_ci  echo 'No $LINUX directory, kernel build skipped.'
1380f66f451Sopenharmony_ci  rmdir "$MYBUILD" "$BUILD" 2>/dev/null
1390f66f451Sopenharmony_ci  exit 0
1400f66f451Sopenharmony_cifi
1410f66f451Sopenharmony_ci
1420f66f451Sopenharmony_ci# Which architecture are we building a kernel for?
1430f66f451Sopenharmony_ci[ -z "$TARGET" ] && TARGET="${CROSS_BASE/-*/}"
1440f66f451Sopenharmony_ci[ -z "$TARGET" ] && TARGET="$(uname -m)"
1450f66f451Sopenharmony_ci
1460f66f451Sopenharmony_ci# Target-specific info in an (alphabetical order) if/else staircase
1470f66f451Sopenharmony_ci# Each target needs board config, serial console, RTC, ethernet, block device.
1480f66f451Sopenharmony_ci
1490f66f451Sopenharmony_ciif [ "$TARGET" == armv5l ]
1500f66f451Sopenharmony_cithen
1510f66f451Sopenharmony_ci
1520f66f451Sopenharmony_ci  # This could use the same VIRT board as armv7, but let's demonstrate a
1530f66f451Sopenharmony_ci  # different one requiring a separate device tree binary.
1540f66f451Sopenharmony_ci  QEMU="qemu-system-arm -M versatilepb -net nic,model=rtl8139 -net user"
1550f66f451Sopenharmony_ci  KARCH=arm
1560f66f451Sopenharmony_ci  KARGS="console=ttyAMA0"
1570f66f451Sopenharmony_ci  VMLINUX=arch/arm/boot/zImage
1580f66f451Sopenharmony_ci  KERNEL_CONFIG="
1590f66f451Sopenharmony_ciCONFIG_CPU_ARM926T=y
1600f66f451Sopenharmony_ciCONFIG_MMU=y
1610f66f451Sopenharmony_ciCONFIG_VFP=y
1620f66f451Sopenharmony_ciCONFIG_ARM_THUMB=y
1630f66f451Sopenharmony_ciCONFIG_AEABI=y
1640f66f451Sopenharmony_ciCONFIG_ARCH_VERSATILE=y
1650f66f451Sopenharmony_ci
1660f66f451Sopenharmony_ci# The switch to device-tree-only added this mess
1670f66f451Sopenharmony_ciCONFIG_ATAGS=y
1680f66f451Sopenharmony_ciCONFIG_DEPRECATED_PARAM_STRUCT=y
1690f66f451Sopenharmony_ciCONFIG_ARM_ATAG_DTB_COMPAT=y
1700f66f451Sopenharmony_ciCONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND=y
1710f66f451Sopenharmony_ci
1720f66f451Sopenharmony_ciCONFIG_SERIAL_AMBA_PL011=y
1730f66f451Sopenharmony_ciCONFIG_SERIAL_AMBA_PL011_CONSOLE=y
1740f66f451Sopenharmony_ci
1750f66f451Sopenharmony_ciCONFIG_RTC_CLASS=y
1760f66f451Sopenharmony_ciCONFIG_RTC_DRV_PL031=y
1770f66f451Sopenharmony_ciCONFIG_RTC_HCTOSYS=y
1780f66f451Sopenharmony_ci
1790f66f451Sopenharmony_ciCONFIG_PCI=y
1800f66f451Sopenharmony_ciCONFIG_PCI_VERSATILE=y
1810f66f451Sopenharmony_ciCONFIG_BLK_DEV_SD=y
1820f66f451Sopenharmony_ciCONFIG_SCSI=y
1830f66f451Sopenharmony_ciCONFIG_SCSI_LOWLEVEL=y
1840f66f451Sopenharmony_ciCONFIG_SCSI_SYM53C8XX_2=y
1850f66f451Sopenharmony_ciCONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE=0
1860f66f451Sopenharmony_ciCONFIG_SCSI_SYM53C8XX_MMIO=y
1870f66f451Sopenharmony_ci
1880f66f451Sopenharmony_ciCONFIG_NET_VENDOR_REALTEK=y
1890f66f451Sopenharmony_ciCONFIG_8139CP=y
1900f66f451Sopenharmony_ci"
1910f66f451Sopenharmony_ci  DTB=arch/arm/boot/dts/versatile-pb.dtb
1920f66f451Sopenharmony_cielif [ "$TARGET" == armv7l ] || [ "$TARGET" == aarch64 ]
1930f66f451Sopenharmony_cithen
1940f66f451Sopenharmony_ci  if [ "$TARGET" == aarch64 ]
1950f66f451Sopenharmony_ci  then
1960f66f451Sopenharmony_ci    QEMU="qemu-system-aarch64 -M virt -cpu cortex-a57"
1970f66f451Sopenharmony_ci    KARCH=arm64
1980f66f451Sopenharmony_ci    VMLINUX=arch/arm64/boot/Image
1990f66f451Sopenharmony_ci  else
2000f66f451Sopenharmony_ci    QEMU="qemu-system-arm -M virt"
2010f66f451Sopenharmony_ci    KARCH=arm
2020f66f451Sopenharmony_ci    VMLINUX=arch/arm/boot/zImage
2030f66f451Sopenharmony_ci  fi
2040f66f451Sopenharmony_ci  KARGS="console=ttyAMA0"
2050f66f451Sopenharmony_ci  KERNEL_CONFIG="
2060f66f451Sopenharmony_ciCONFIG_MMU=y
2070f66f451Sopenharmony_ciCONFIG_ARCH_MULTI_V7=y
2080f66f451Sopenharmony_ciCONFIG_ARCH_VIRT=y
2090f66f451Sopenharmony_ciCONFIG_SOC_DRA7XX=y
2100f66f451Sopenharmony_ciCONFIG_ARCH_OMAP2PLUS_TYPICAL=y
2110f66f451Sopenharmony_ciCONFIG_ARCH_ALPINE=y
2120f66f451Sopenharmony_ciCONFIG_ARM_THUMB=y
2130f66f451Sopenharmony_ciCONFIG_VDSO=y
2140f66f451Sopenharmony_ciCONFIG_CPU_IDLE=y
2150f66f451Sopenharmony_ciCONFIG_ARM_CPUIDLE=y
2160f66f451Sopenharmony_ciCONFIG_KERNEL_MODE_NEON=y
2170f66f451Sopenharmony_ci
2180f66f451Sopenharmony_ciCONFIG_SERIAL_AMBA_PL011=y
2190f66f451Sopenharmony_ciCONFIG_SERIAL_AMBA_PL011_CONSOLE=y
2200f66f451Sopenharmony_ci
2210f66f451Sopenharmony_ciCONFIG_RTC_CLASS=y
2220f66f451Sopenharmony_ciCONFIG_RTC_HCTOSYS=y
2230f66f451Sopenharmony_ciCONFIG_RTC_DRV_PL031=y
2240f66f451Sopenharmony_ci
2250f66f451Sopenharmony_ciCONFIG_NET_CORE=y
2260f66f451Sopenharmony_ciCONFIG_VIRTIO_MENU=y
2270f66f451Sopenharmony_ciCONFIG_VIRTIO_NET=y
2280f66f451Sopenharmony_ci
2290f66f451Sopenharmony_ciCONFIG_PCI=y
2300f66f451Sopenharmony_ciCONFIG_PCI_HOST_GENERIC=y
2310f66f451Sopenharmony_ciCONFIG_VIRTIO_BLK=y
2320f66f451Sopenharmony_ciCONFIG_VIRTIO_PCI=y
2330f66f451Sopenharmony_ciCONFIG_VIRTIO_MMIO=y
2340f66f451Sopenharmony_ci
2350f66f451Sopenharmony_ciCONFIG_ATA=y
2360f66f451Sopenharmony_ciCONFIG_ATA_SFF=y
2370f66f451Sopenharmony_ciCONFIG_ATA_BMDMA=y
2380f66f451Sopenharmony_ciCONFIG_ATA_PIIX=y
2390f66f451Sopenharmony_ci
2400f66f451Sopenharmony_ciCONFIG_PATA_PLATFORM=y
2410f66f451Sopenharmony_ciCONFIG_PATA_OF_PLATFORM=y
2420f66f451Sopenharmony_ciCONFIG_ATA_GENERIC=y
2430f66f451Sopenharmony_ci"
2440f66f451Sopenharmony_cielif [ "$TARGET" == i486 ] || [ "$TARGET" == i686 ] ||
2450f66f451Sopenharmony_ci     [ "$TARGET" == x86_64 ] || [ "$TARGET" == x32 ]
2460f66f451Sopenharmony_cithen
2470f66f451Sopenharmony_ci  if [ "$TARGET" == i486 ]
2480f66f451Sopenharmony_ci  then
2490f66f451Sopenharmony_ci    QEMU="qemu-system-i386 -cpu 486 -global fw_cfg.dma_enabled=false"
2500f66f451Sopenharmony_ci    KERNEL_CONFIG="CONFIG_M486=y"
2510f66f451Sopenharmony_ci  elif [ "$TARGET" == i686 ]
2520f66f451Sopenharmony_ci  then
2530f66f451Sopenharmony_ci    QEMU="qemu-system-i386 -cpu pentium3"
2540f66f451Sopenharmony_ci    KERNEL_CONFIG="CONFIG_MPENTIUMII=y"
2550f66f451Sopenharmony_ci  else
2560f66f451Sopenharmony_ci    QEMU=qemu-system-x86_64
2570f66f451Sopenharmony_ci    KERNEL_CONFIG="CONFIG_64BIT=y"
2580f66f451Sopenharmony_ci    [ "$TARGET" == x32 ] && KERNEL_CONFIG="$KERNEL_CONFIG
2590f66f451Sopenharmony_ciCONFIG_X86_X32=y"
2600f66f451Sopenharmony_ci  fi
2610f66f451Sopenharmony_ci  KARCH=x86
2620f66f451Sopenharmony_ci  KARGS="console=ttyS0"
2630f66f451Sopenharmony_ci  VMLINUX=arch/x86/boot/bzImage
2640f66f451Sopenharmony_ci  CONFIG_MPENTIUMII=y
2650f66f451Sopenharmony_ci  KERNEL_CONFIG="
2660f66f451Sopenharmony_ci$KERNEL_CONFIG
2670f66f451Sopenharmony_ci
2680f66f451Sopenharmony_ciCONFIG_UNWINDER_FRAME_POINTER=y
2690f66f451Sopenharmony_ci
2700f66f451Sopenharmony_ciCONFIG_PCI=y
2710f66f451Sopenharmony_ciCONFIG_BLK_DEV_SD=y
2720f66f451Sopenharmony_ciCONFIG_ATA=y
2730f66f451Sopenharmony_ciCONFIG_ATA_SFF=y
2740f66f451Sopenharmony_ciCONFIG_ATA_BMDMA=y
2750f66f451Sopenharmony_ciCONFIG_ATA_PIIX=y
2760f66f451Sopenharmony_ci
2770f66f451Sopenharmony_ciCONFIG_NET_VENDOR_INTEL=y
2780f66f451Sopenharmony_ciCONFIG_E1000=y
2790f66f451Sopenharmony_ciCONFIG_SERIAL_8250=y
2800f66f451Sopenharmony_ciCONFIG_SERIAL_8250_CONSOLE=y
2810f66f451Sopenharmony_ciCONFIG_RTC_CLASS=y
2820f66f451Sopenharmony_ci"
2830f66f451Sopenharmony_cielif [ "$TARGET" == mips ] || [ "$TARGET" == mipsel ]
2840f66f451Sopenharmony_cithen
2850f66f451Sopenharmony_ci  QEMU="qemu-system-mips -M malta"
2860f66f451Sopenharmony_ci  KARCH=mips
2870f66f451Sopenharmony_ci  KARGS="console=ttyS0"
2880f66f451Sopenharmony_ci  VMLINUX=vmlinux
2890f66f451Sopenharmony_ci  KERNEL_CONFIG="
2900f66f451Sopenharmony_ciCONFIG_MIPS_MALTA=y
2910f66f451Sopenharmony_ciCONFIG_CPU_MIPS32_R2=y
2920f66f451Sopenharmony_ciCONFIG_SERIAL_8250=y
2930f66f451Sopenharmony_ciCONFIG_SERIAL_8250_CONSOLE=y
2940f66f451Sopenharmony_ci
2950f66f451Sopenharmony_ciCONFIG_PCI=y
2960f66f451Sopenharmony_ciCONFIG_BLK_DEV_SD=y
2970f66f451Sopenharmony_ciCONFIG_ATA=y
2980f66f451Sopenharmony_ciCONFIG_ATA_SFF=y
2990f66f451Sopenharmony_ciCONFIG_ATA_BMDMA=y
3000f66f451Sopenharmony_ciCONFIG_ATA_PIIX=y
3010f66f451Sopenharmony_ci
3020f66f451Sopenharmony_ciCONFIG_NET_VENDOR_AMD=y
3030f66f451Sopenharmony_ciCONFIG_PCNET32=y
3040f66f451Sopenharmony_ci
3050f66f451Sopenharmony_ciCONFIG_POWER_RESET=y
3060f66f451Sopenharmony_ciCONFIG_POWER_RESET_SYSCON=y
3070f66f451Sopenharmony_ci"
3080f66f451Sopenharmony_ci  [ "$TARGET" == mipsel ] &&
3090f66f451Sopenharmony_ci    KERNEL_CONFIG="${KERNEL_CONFIG}CONFIG_CPU_LITTLE_ENDIAN=y" &&
3100f66f451Sopenharmony_ci    QEMU="qemu-system-mipsel -M malta"
3110f66f451Sopenharmony_cielif [ "$TARGET" == powerpc ]
3120f66f451Sopenharmony_cithen
3130f66f451Sopenharmony_ci  KARCH=powerpc
3140f66f451Sopenharmony_ci  QEMU="qemu-system-ppc -M g3beige"
3150f66f451Sopenharmony_ci  KARGS="console=ttyS0"
3160f66f451Sopenharmony_ci  VMLINUX=vmlinux
3170f66f451Sopenharmony_ci  KERNEL_CONFIG="
3180f66f451Sopenharmony_ciCONFIG_ALTIVEC=y
3190f66f451Sopenharmony_ciCONFIG_PPC_PMAC=y
3200f66f451Sopenharmony_ciCONFIG_PPC_OF_BOOT_TRAMPOLINE=y
3210f66f451Sopenharmony_ci
3220f66f451Sopenharmony_ciCONFIG_IDE=y
3230f66f451Sopenharmony_ciCONFIG_IDE_GD=y
3240f66f451Sopenharmony_ciCONFIG_IDE_GD_ATA=y
3250f66f451Sopenharmony_ciCONFIG_BLK_DEV_IDE_PMAC=y
3260f66f451Sopenharmony_ciCONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST=y
3270f66f451Sopenharmony_ci
3280f66f451Sopenharmony_ciCONFIG_MACINTOSH_DRIVERS=y
3290f66f451Sopenharmony_ciCONFIG_ADB=y
3300f66f451Sopenharmony_ciCONFIG_ADB_CUDA=y
3310f66f451Sopenharmony_ci
3320f66f451Sopenharmony_ciCONFIG_NET_VENDOR_NATSEMI=y
3330f66f451Sopenharmony_ciCONFIG_NET_VENDOR_8390=y
3340f66f451Sopenharmony_ciCONFIG_NE2K_PCI=y
3350f66f451Sopenharmony_ci
3360f66f451Sopenharmony_ciCONFIG_SERIO=y
3370f66f451Sopenharmony_ciCONFIG_SERIAL_PMACZILOG=y
3380f66f451Sopenharmony_ciCONFIG_SERIAL_PMACZILOG_TTYS=y
3390f66f451Sopenharmony_ciCONFIG_SERIAL_PMACZILOG_CONSOLE=y
3400f66f451Sopenharmony_ciCONFIG_BOOTX_TEXT=y
3410f66f451Sopenharmony_ci"
3420f66f451Sopenharmony_cielif [ "$TARGET" == powerpc64le ]
3430f66f451Sopenharmony_cithen
3440f66f451Sopenharmony_ci  KARCH=powerpc
3450f66f451Sopenharmony_ci  QEMU="qemu-system-ppc64 -M pseries -vga none"
3460f66f451Sopenharmony_ci  KARGS="console=/dev/hvc0"
3470f66f451Sopenharmony_ci  VMLINUX=vmlinux
3480f66f451Sopenharmony_ci  KERNEL_CONFIG="CONFIG_PPC64=y
3490f66f451Sopenharmony_ciCONFIG_PPC_PSERIES=y
3500f66f451Sopenharmony_ciCONFIG_CPU_LITTLE_ENDIAN=y
3510f66f451Sopenharmony_ciCONFIG_PPC_OF_BOOT_TRAMPOLINE=y
3520f66f451Sopenharmony_ci
3530f66f451Sopenharmony_ciCONFIG_BLK_DEV_SD=y
3540f66f451Sopenharmony_ciCONFIG_SCSI_LOWLEVEL=y
3550f66f451Sopenharmony_ciCONFIG_SCSI_IBMVSCSI=y
3560f66f451Sopenharmony_ciCONFIG_ATA=y
3570f66f451Sopenharmony_ci
3580f66f451Sopenharmony_ciCONFIG_NET_VENDOR_IBM=y
3590f66f451Sopenharmony_ciCONFIG_IBMVETH=y
3600f66f451Sopenharmony_ciCONFIG_HVC_CONSOLE=y
3610f66f451Sopenharmony_ci
3620f66f451Sopenharmony_ci# None of this should be necessary
3630f66f451Sopenharmony_ciCONFIG_PPC_TRANSACTIONAL_MEM=y
3640f66f451Sopenharmony_ciCONFIG_PPC_DISABLE_WERROR=y
3650f66f451Sopenharmony_ciCONFIG_SECTION_MISMATCH_WARN_ONLY=y
3660f66f451Sopenharmony_ci"
3670f66f451Sopenharmony_cielif [ "$TARGET" = s390x ]
3680f66f451Sopenharmony_cithen
3690f66f451Sopenharmony_ci  QEMU="qemu-system-s390x"
3700f66f451Sopenharmony_ci  KARCH=s390
3710f66f451Sopenharmony_ci  VMLINUX=arch/s390/boot/bzImage
3720f66f451Sopenharmony_ci  KERNEL_CONFIG="
3730f66f451Sopenharmony_ciCONFIG_MARCH_Z900=y
3740f66f451Sopenharmony_ciCONFIG_PACK_STACK=y
3750f66f451Sopenharmony_ciCONFIG_NET_CORE=y
3760f66f451Sopenharmony_ciCONFIG_VIRTIO_NET=y
3770f66f451Sopenharmony_ciCONFIG_VIRTIO_BLK=y
3780f66f451Sopenharmony_ciCONFIG_SCLP_TTY=y
3790f66f451Sopenharmony_ciCONFIG_SCLP_CONSOLE=y
3800f66f451Sopenharmony_ciCONFIG_SCLP_VT220_TTY=y
3810f66f451Sopenharmony_ciCONFIG_SCLP_VT220_CONSOLE=y
3820f66f451Sopenharmony_ciCONFIG_S390_GUEST=y
3830f66f451Sopenharmony_ci"
3840f66f451Sopenharmony_cielif [ "$TARGET" == sh4 ]
3850f66f451Sopenharmony_cithen
3860f66f451Sopenharmony_ci  QEMU="qemu-system-sh4 -M r2d -serial null -serial mon:stdio"
3870f66f451Sopenharmony_ci  KARCH=sh
3880f66f451Sopenharmony_ci  KARGS="console=ttySC1 noiotrap"
3890f66f451Sopenharmony_ci  VMLINUX=arch/sh/boot/zImage
3900f66f451Sopenharmony_ci  KERNEL_CONFIG="
3910f66f451Sopenharmony_ciCONFIG_CPU_SUBTYPE_SH7751R=y
3920f66f451Sopenharmony_ciCONFIG_MMU=y
3930f66f451Sopenharmony_ciCONFIG_MEMORY_START=0x0c000000
3940f66f451Sopenharmony_ciCONFIG_VSYSCALL=y
3950f66f451Sopenharmony_ciCONFIG_SH_FPU=y
3960f66f451Sopenharmony_ciCONFIG_SH_RTS7751R2D=y
3970f66f451Sopenharmony_ciCONFIG_RTS7751R2D_PLUS=y
3980f66f451Sopenharmony_ciCONFIG_SERIAL_SH_SCI=y
3990f66f451Sopenharmony_ciCONFIG_SERIAL_SH_SCI_CONSOLE=y
4000f66f451Sopenharmony_ci
4010f66f451Sopenharmony_ciCONFIG_PCI=y
4020f66f451Sopenharmony_ciCONFIG_NET_VENDOR_REALTEK=y
4030f66f451Sopenharmony_ciCONFIG_8139CP=y
4040f66f451Sopenharmony_ci
4050f66f451Sopenharmony_ciCONFIG_PCI=y
4060f66f451Sopenharmony_ciCONFIG_BLK_DEV_SD=y
4070f66f451Sopenharmony_ciCONFIG_ATA=y
4080f66f451Sopenharmony_ciCONFIG_ATA_SFF=y
4090f66f451Sopenharmony_ciCONFIG_ATA_BMDMA=y
4100f66f451Sopenharmony_ciCONFIG_PATA_PLATFORM=y
4110f66f451Sopenharmony_ci
4120f66f451Sopenharmony_ciCONFIG_BINFMT_ELF_FDPIC=y
4130f66f451Sopenharmony_ciCONFIG_BINFMT_FLAT=y
4140f66f451Sopenharmony_ci
4150f66f451Sopenharmony_ci#CONFIG_SPI=y
4160f66f451Sopenharmony_ci#CONFIG_SPI_SH_SCI=y
4170f66f451Sopenharmony_ci#CONFIG_MFD_SM501=y
4180f66f451Sopenharmony_ci
4190f66f451Sopenharmony_ci#CONFIG_RTC_CLASS=y
4200f66f451Sopenharmony_ci#CONFIG_RTC_DRV_R9701=y
4210f66f451Sopenharmony_ci#CONFIG_RTC_DRV_SH=y
4220f66f451Sopenharmony_ci#CONFIG_RTC_HCTOSYS=y
4230f66f451Sopenharmony_ci"
4240f66f451Sopenharmony_cielse
4250f66f451Sopenharmony_ci  echo "Unknown \$TARGET"
4260f66f451Sopenharmony_ci  exit 1
4270f66f451Sopenharmony_cifi
4280f66f451Sopenharmony_ci
4290f66f451Sopenharmony_ci# Write the miniconfig file
4300f66f451Sopenharmony_ci{
4310f66f451Sopenharmony_ci  echo "# make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG=$TARGET.miniconf"
4320f66f451Sopenharmony_ci  echo "# make ARCH=$KARCH -j \$(nproc)"
4330f66f451Sopenharmony_ci  echo "# boot $VMLINUX"
4340f66f451Sopenharmony_ci  echo
4350f66f451Sopenharmony_ci  echo "$KERNEL_CONFIG"
4360f66f451Sopenharmony_ci
4370f66f451Sopenharmony_ci  # Generic options for all targets
4380f66f451Sopenharmony_ci
4390f66f451Sopenharmony_ci  echo "
4400f66f451Sopenharmony_ci# CONFIG_EMBEDDED is not set
4410f66f451Sopenharmony_ciCONFIG_EARLY_PRINTK=y
4420f66f451Sopenharmony_ciCONFIG_BINFMT_ELF=y
4430f66f451Sopenharmony_ciCONFIG_BINFMT_SCRIPT=y
4440f66f451Sopenharmony_ciCONFIG_NO_HZ=y
4450f66f451Sopenharmony_ciCONFIG_HIGH_RES_TIMERS=y
4460f66f451Sopenharmony_ci
4470f66f451Sopenharmony_ciCONFIG_BLK_DEV=y
4480f66f451Sopenharmony_ciCONFIG_BLK_DEV_INITRD=y
4490f66f451Sopenharmony_ciCONFIG_RD_GZIP=y
4500f66f451Sopenharmony_ci
4510f66f451Sopenharmony_ciCONFIG_BLK_DEV_LOOP=y
4520f66f451Sopenharmony_ciCONFIG_EXT4_FS=y
4530f66f451Sopenharmony_ciCONFIG_EXT4_USE_FOR_EXT2=y
4540f66f451Sopenharmony_ciCONFIG_VFAT_FS=y
4550f66f451Sopenharmony_ciCONFIG_FAT_DEFAULT_UTF8=y
4560f66f451Sopenharmony_ciCONFIG_MISC_FILESYSTEMS=y
4570f66f451Sopenharmony_ciCONFIG_SQUASHFS=y
4580f66f451Sopenharmony_ciCONFIG_SQUASHFS_XATTR=y
4590f66f451Sopenharmony_ciCONFIG_SQUASHFS_ZLIB=y
4600f66f451Sopenharmony_ciCONFIG_DEVTMPFS=y
4610f66f451Sopenharmony_ciCONFIG_DEVTMPFS_MOUNT=y
4620f66f451Sopenharmony_ciCONFIG_TMPFS=y
4630f66f451Sopenharmony_ciCONFIG_TMPFS_POSIX_ACL=y
4640f66f451Sopenharmony_ci
4650f66f451Sopenharmony_ciCONFIG_NET=y
4660f66f451Sopenharmony_ciCONFIG_PACKET=y
4670f66f451Sopenharmony_ciCONFIG_UNIX=y
4680f66f451Sopenharmony_ciCONFIG_INET=y
4690f66f451Sopenharmony_ciCONFIG_IPV6=y
4700f66f451Sopenharmony_ciCONFIG_NETDEVICES=y
4710f66f451Sopenharmony_ci#CONFIG_NET_CORE=y
4720f66f451Sopenharmony_ci#CONFIG_NETCONSOLE=y
4730f66f451Sopenharmony_ciCONFIG_ETHERNET=y
4740f66f451Sopenharmony_ci"
4750f66f451Sopenharmony_ci} > "$OUTPUT/miniconfig-$TARGET"
4760f66f451Sopenharmony_ci
4770f66f451Sopenharmony_ci# Write the qemu launch script
4780f66f451Sopenharmony_ciecho "$QEMU -nographic -no-reboot -m 256" \
4790f66f451Sopenharmony_ci     "-append \"panic=1 HOST=$TARGET $KARGS\"" \
4800f66f451Sopenharmony_ci     "-kernel $(basename "$VMLINUX") -initrd ${CROSS_BASE}root.cpio.gz" \
4810f66f451Sopenharmony_ci     ${DTB:+-dtb "$(basename "$DTB")"} '"$@"' \
4820f66f451Sopenharmony_ci     > "$OUTPUT/qemu-$TARGET.sh" &&
4830f66f451Sopenharmony_cichmod +x "$OUTPUT/qemu-$TARGET.sh" &&
4840f66f451Sopenharmony_ci
4850f66f451Sopenharmony_ciecho "Build linux for $KARCH"
4860f66f451Sopenharmony_ci
4870f66f451Sopenharmony_ci# Snapshot Linux source dir and clean it
4880f66f451Sopenharmony_cicp -sfR "$LINUX" "$MYBUILD/linux" && pushd "$MYBUILD/linux" > /dev/null ||
4890f66f451Sopenharmony_ci  exit 1
4900f66f451Sopenharmony_ci
4910f66f451Sopenharmony_ci# Build kernel
4920f66f451Sopenharmony_cimake distclean &&
4930f66f451Sopenharmony_cimake ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG="$OUTPUT/miniconfig-$TARGET" &&
4940f66f451Sopenharmony_cimake ARCH=$KARCH CROSS_COMPILE="$CROSS_COMPILE" -j $(nproc) || exit 1
4950f66f451Sopenharmony_ci
4960f66f451Sopenharmony_ci# If we have a device tree binary, save it for QEMU.
4970f66f451Sopenharmony_ciif [ ! -z "$DTB" ]
4980f66f451Sopenharmony_cithen
4990f66f451Sopenharmony_ci  cp "$DTB" "$OUTPUT/$(basename "$DTB")" || exit 1
5000f66f451Sopenharmony_cifi
5010f66f451Sopenharmony_ci
5020f66f451Sopenharmony_cicp "$VMLINUX" "$OUTPUT/$(basename "$VMLINUX")" && cd .. && rm -rf linux &&
5030f66f451Sopenharmony_ci  popd || exit 1
5040f66f451Sopenharmony_cirmdir "$MYBUILD" "$BUILD" 2>/dev/null
5050f66f451Sopenharmony_ci
5060f66f451Sopenharmony_ci# package root filesystem for initramfs.
5070f66f451Sopenharmony_ci# we do it here so module install can add files (not implemented yet)
5080f66f451Sopenharmony_ciecho === create "${CROSS_BASE}root.cpio.gz"
5090f66f451Sopenharmony_ci
5100f66f451Sopenharmony_ci(cd "$ROOT" && find . | cpio -o -H newc | gzip) > \
5110f66f451Sopenharmony_ci  "$OUTPUT/${CROSS_BASE}root.cpio.gz"
512