# GNU Make >= 3.82
# GCC ;)
-TARGET_ARCH ?= x86_64
+TARGET_ARCH := arm
+TARGET_CROSS := armv4t-softfloat-linux-gnueabi
+TOOLCHAIN_PREFIX :=
+TARGET_CROSS_PREFIX := ${TARGET_CROSS}
+
+ifndef TOOLCHAIN_PREFIX
+TOOLCHAIN_PREFIX := /opt/arm
+endif
+
+ifndef TARGET_CROSS_PREFIX
+TARGET_CROSS_PREFIX := ${TOOLCHAIN_PREFIX}/bin/${TARGET_CROSS}
+endif
ifndef PARALLEL
ifndef NOPARALLEL
.PHONY: world
-world: ${SYSROOT}/bin/busybox \
+world: \
+ build-linux/arch/arm/boot/zImage \
+ ${SYSROOT}/lib/modules \
${SYSROOT}/etc/group \
${SYSROOT}/etc/passwd \
${SYSROOT}/etc/inittab \
${SYSROOT}/init \
${SYSROOT}/loginroot \
- build-linux/arch/x86_64/boot/bzImage \
- ${SYSROOT}/lib/modules \
- initramfs.cpio.xz
+ ${SYSROOT}/usr/bin/lsgpio
-# --- kernel
+# --- linux
-build-linux/arch/x86/configs:
+.PHONY: .build-linux .install-modules .dtbs_check .dt_binding_check
+
+build-linux/arch/arm/configs:
mkdir -p $@
-.PHONY: kernel
+build-linux/arch/arm/configs/ts7250_defconfig: configs/kernel/arch/arm/configs/ts7250_defconfig | build-linux/arch/arm/configs
+ cp $< $@
+
+build-linux/.config: build-linux/arch/arm/configs/ts7250_defconfig
+ make ARCH=${TARGET_ARCH} -C ${KERNEL_TREE} O=${CURDIR}/build-linux ts7250_defconfig
-build-linux/arch/x86/configs/x86_64_qemu_defconfig: | build-linux/arch/x86/configs configs/x86_64_qemu_defconfig
- cp configs/x86_64_qemu_defconfig $@
+build-linux/arch/arm/boot/zImage: build-linux/.config linux
+ make ${PARALLEL} -C build-linux ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- V=1 -s
-build-linux/.config: | build-linux/arch/x86/configs/x86_64_qemu_defconfig
- make ARCH=${TARGET_ARCH} -C ${KERNEL_TREE} O=${CURDIR}/build-linux x86_64_qemu_defconfig
+.dtbs_check:
+ PATH="${CURDIR}/dt-schema/tools/:${PATH}" \
+ make -C build-linux ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- dtbs_check
-build-linux/arch/x86_64/boot/bzImage: build-linux/.config
- make ${PARALLEL} -C build-linux ARCH=${TARGET_ARCH} V=1
+.dt_binding_check:
+ PATH="${CURDIR}/dt-schema/tools/:${PATH}" \
+ make -C build-linux ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- dt_binding_check
-.PHONY: .install-modules
+.build-linux: build-linux/arch/arm/boot/zImage
-${SYSROOT}/lib/modules: build-linux/arch/x86_64/boot/bzImage
- make ${PARALLEL} -C build-linux INSTALL_MOD_PATH=${SYSROOT} modules_install
+${SYSROOT}/lib/modules: build-linux/arch/arm/boot/Image
+ make ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- ${PARALLEL} -s -C build-linux INSTALL_MOD_PATH=${SYSROOT} INSTALL_MOD_STRIP=1 modules_install
.install-modules: ${SYSROOT}/lib/modules ${SYSROOT}/.mount-stamp
distclean::
-rm -rf build-linux
+# --- gpio-tools
+
+.PHONY: .gpio-tools
+
+build-linux/tools/gpio:
+ mkdir -p $@
+
+${SYSROOT}/usr/bin/lsgpio: build-linux/tools/gpio
+ LDFLAGS="-static" make -C linux/tools/gpio/ O=build-linux/tools/gpio DESTDIR=${SYSROOT} ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- V=1 install
+
+.gpio-tools: ${SYSROOT}/usr/bin/lsgpio
+
+clean::
+ -rm -rf ${SYSROOT}/usr/bin/lsgpio
+ -rm -rf ${SYSROOT}/usr/bin/gpio-watch
+ -rm -rf ${SYSROOT}/usr/bin/gpio-event-mon
+ -rm -rf ${SYSROOT}/usr/bin/gpio-hammer
+
# --- initramfs
CREATE_DIRS := \
- /dev \
- /dev/pts \
- /boot \
- /etc \
- /home \
- /mnt \
- /opt \
- /proc \
- /root \
- /srv \
- /sys \
- /usr \
- /var \
- /var/log \
- /run \
- /tmp \
- /lib
-
-$(patsubst %,${SYSROOT}%,${CREATE_DIRS}): ${SYSROOT}/.mount-stamp
+ /dev \
+ /dev/pts \
+ /boot \
+ /etc \
+ /home \
+ /mnt \
+ /opt \
+ /proc \
+ /root \
+ /srv \
+ /sys \
+ /usr \
+ /var \
+ /var/log \
+ /run \
+ /tmp \
+ /lib
+
+$(patsubst %,${SYSROOT}%,${CREATE_DIRS}): ${SYSROOT}/.mount-stamp
install -d -m 0755 $@
-.PHONY: populate-dirs
+.PHONY: populate-dirs
-populate-dirs: | $(patsubst %,${SYSROOT}%,${CREATE_DIRS})
+populate-dirs: | $(patsubst %,${SYSROOT}%,${CREATE_DIRS})
-${SYSROOT}/etc/passwd: etc/passwd ${SYSROOT}/.mount-stamp | ${SYSROOT}/etc
+${SYSROOT}/etc/passwd: etc/passwd ${SYSROOT}/.mount-stamp | ${SYSROOT}/etc
install -m 644 $< $@
-${SYSROOT}/etc/group: etc/group ${SYSROOT}/.mount-stamp | ${SYSROOT}/etc
+${SYSROOT}/etc/passwd: etc/passwd ${SYSROOT}/.mount-stamp | ${SYSROOT}/etc
install -m 644 $< $@
-${SYSROOT}/etc/inittab: etc/inittab ${SYSROOT}/.mount-stamp | ${SYSROOT}/etc
+${SYSROOT}/etc/group: etc/group ${SYSROOT}/.mount-stamp | ${SYSROOT}/etc
install -m 644 $< $@
-${SYSROOT}/init: scripts/init | ${SYSROOT}
+${SYSROOT}/etc/inittab: etc/inittab ${SYSROOT}/.mount-stamp | ${SYSROOT}/etc
+ install -m 644 $< $@
+
+${SYSROOT}/init: scripts/init | ${SYSROOT}
install -m 755 $< $@
-${SYSROOT}/loginroot: scripts/loginroot | ${SYSROOT}
+${SYSROOT}/loginroot: scripts/loginroot | ${SYSROOT}
install -m 755 $< $@
# --- busybox
build-busybox:
mkdir $@
-busybox/configs/qemu_defconfig: configs/busybox_config
+busybox/configs/ts7250_defconfig: configs/busybox_config
cp $< $@
-build-busybox/.config: busybox/configs/qemu_defconfig | build-busybox
- make -C busybox O=../build-busybox ARCH=${TARGET_ARCH} qemu_defconfig
+build-busybox/.config: busybox/configs/ts7250_defconfig | build-busybox
+ make -C busybox O=../build-busybox ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- defconfig
build-busybox/busybox: build-busybox/.config
- make ${PARALLEL} -C build-busybox ARCH=${TARGET_ARCH}
+ make -C build-busybox ${PARALLEL} ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- V=1
${SYSROOT}/bin/busybox: build-busybox/busybox | populate-dirs
- make ${PARALLEL} -C build-busybox ARCH=${TARGET_ARCH} CONFIG_PREFIX=${SYSROOT} install
+ make -C build-busybox ${PARALLEL} ARCH=${TARGET_ARCH} CROSS_COMPILE=${TARGET_CROSS_PREFIX}- CONFIG_PREFIX=${SYSROOT} install
rm -rf ${SYSROOT}/linuxrc
.PHONY: .install-busybox
distclean::
rm -rf build-busybox
-initramfs.cpio.xz: ${SYSROOT}/bin/busybox ${SYSROOT}/loginroot ${SYSROOT}/init ${SYSROOT}/etc/inittab ${SYSROOT}/etc/group ${SYSROOT}/etc/passwd .install-modules
- (cd ${SYSROOT} && find . -print0 | cpio --null -ov --format=newc | xz -C crc32 > ../initramfs.cpio.xz)
+initramfs: ${SYSROOT}/bin/busybox ${SYSROOT}/loginroot ${SYSROOT}/init ${SYSROOT}/etc/inittab ${SYSROOT}/etc/group ${SYSROOT}/etc/passwd populate-dirs
+
+.PHONY: build-image-clean
+
+build-image:
+ mkdir -p $@
+
+build-image-clean: initramfs | build-image
+ rm -rf build-image/rootfs
+ mkdir build-image/rootfs
+ (cd ${SYSROOT} && tar cf - . ) | (cd build-image/rootfs; tar xf - )
+ rm -rf build-image/rootfs/usr/{include,share/doc,share/info}
+ rm -rf build-image/rootfs/var/db/*
+ rm -rf build-image/rootfs/var/lib/*
+ rm -rf build-image/rootfs/var/log/*
+ rm -rf build-image/rootfs/var/run/*
+ rm -rf build-image/rootfs/usr/share/man
+ rm -rf build-image/rootfs/usr/local/share/man
+ rm -rf build-image/rootfs/usr/share/pkgconfig build-image/rootfs/usr/lib/pkgconfig
+ rm -rf build-image/rootfs/usr/share/locale/{el,ko,sl,be,eo,bs,nb,pt,tr,ro,uk,it,hu,sv,id,kk,es,zh_CN,da,de,vi,pt_BR,nl,en_GB,ia,sq,sr,af,ru,pl,cs,tl,dz,sk,ja,nn,he,fr,zh_TW,km,gl,fi,eu,ga,lt,hr,bg,rw,ca,et,ne}
+ rm -rf build-image/rootfs/etc/ssl/man
+ find build-image/rootfs \( -name "*.a" -o -name "*.la" -o -name "*.o" \) -exec rm -rf {} \;
+ rm -f build-image/rootfs/usr/bin/{strings,strip,ranlib,readelf,objdump,objcopy,nm,ld.gold,ld.bfd,ld}
+ rm -f build-image/rootfs/usr/bin/{gdb,gdbserver,gprof,flex++,flex,c++filt,as,ar,addr2line}
+ rm -f build-image/rootfs/usr/bin/{strace,strace-graph,strace-log-merge}
+ rm -f build-image/rootfs/bin/udevadm
+ rm -f build-image/rootfs/sbin/{udevd,udevadm}
+ rm -rf build-image/rootfs/etc/udev
+ rm -rf build-image/rootfs/lib/udev
+ find build-image/rootfs -path build-image/rootfs/lib/modules -prune -o -type f -print | while read f; do file $$f | grep -q 'ELF 32-bit MSB' && { ${TARGET_CROSS_PREFIX}-strip -s -p $$f || true; } || true; done
+
+rootfs.ubifs: build-image-clean
+ mkfs -t ubifs -r build-image/rootfs -m 2048 -e 126976 -c 1338 -l 3 -o $@
clean::
- -rm -rf initramfs.cpio.xz
+ -rm -rf rootfs.ubifs
distclean::
- rm -rf ${SYSROOT}
+ -rm -rf ${SYSROOT}