@@ -205,9 +205,9 @@ if $(echo $stages | grep -q ck); then
205205 rm -fr ${basedir} /kernel_pkg
206206 echo remove old kernel_pkg folder
207207 fi
208- if [ -f ${basedir} /kernel.bin ]; then
209- rm -f ${basedir} /kernel.bin
210- echo remove previous builded kernel.bin
208+ if [ -f ${basedir} /kernel_image ]; then
209+ rm -f ${basedir} /kernel_image
210+ echo remove previous builded kernel_image
211211 fi
212212 if [ -f ${basedir} /zImage ]; then
213213 rm -fr ${basedir} /zImage
@@ -254,12 +254,12 @@ forcing some optimization flags
254254 mkdir ${basedir} /kernel_pkg
255255 mkdir ${basedir} /kernel_pkg/boot
256256 mkdir ${basedir} /kernel_pkg/boot/dtbs
257- mkdir ${basedir} /kernel_pkg/boot/re-signing
257+ mkdir ${basedir} /kernel_pkg/boot/reflash
258258 mkdir ${basedir} /kernel_pkg/usr
259259 mkdir ${basedir} /kernel_pkg/DEBIAN
260260
261261 make modules_install INSTALL_MOD_PATH=${basedir} /kernel_pkg
262- make headers_install INSTALL_HDR_PATH=${basedir} /kernel_pkg/usr
262+ # make headers_install INSTALL_HDR_PATH=${basedir}/kernel_pkg/usr
263263 cp -f arch/arm/boot/dts/exynos5250-snow.dtb ${basedir} /kernel_pkg/boot/dtbs/exynos5250-snow.dtb
264264 cp -f arch/arm/boot/dts/exynos5250-snow-rev5.dtb ${basedir} /kernel_pkg/boot/dtbs/exynos5250-snow-rev5.dtb
265265 cp -f arch/arm/boot/zImage ${basedir} /kernel_pkg/boot/zImage
@@ -273,10 +273,10 @@ forcing some optimization flags
273273 ln -s /usr/src/kernel source
274274
275275 cd ${basedir} /kernel_pkg/boot
276- curl -o re-signing /kernel.keyblock https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/master/core/linux-armv7/kernel.keyblock
277- curl -o re-signing /kernel_data_key.vbprivk https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/master/core/linux-armv7/kernel_data_key.vbprivk
276+ curl -o reflash /kernel.keyblock https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/master/core/linux-armv7/kernel.keyblock
277+ curl -o reflash /kernel_data_key.vbprivk https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/master/core/linux-armv7/kernel_data_key.vbprivk
278278
279- cat << __EOF__ > re-signing /kernel-exynos.its
279+ cat << __EOF__ > reflash /kernel-exynos.its
280280/dts-v1/;
281281
282282/ {
@@ -328,43 +328,139 @@ cat << __EOF__ > re-signing/kernel-exynos.its
328328
329329__EOF__
330330
331- echo ' console=tty0 root=PARTUUID=%U/PARTNROFF=1 zswap.compressor=zstd zswap.max_pool_percent=40 noinitrd rootwait' > re-signing /cmdline
332- dd if=/dev/zero of=re-signing /bootloader.bin bs=512 count=1
331+ echo ' console=tty0 root=PARTUUID=%U/PARTNROFF=1 zswap.compressor=zstd zswap.max_pool_percent=40 noinitrd rootwait quiet loglevel=0 ' > reflash /cmdline
332+ dd if=/dev/zero of=reflash /bootloader.bin bs=512 count=1
333333
334334 echo ' #!/bin/bash
335335echo ""
336336echo re-signing kernel image
337- if [ -f kernel.bin ]; then
338- echo backing up existed image
339- mv -f kernel.bin kernel.bin.bak;
340- echo you may restore it from kernel.bin.bak
341- fi
342337echo ""
343338sleep 5
344339
345- mkimage -D "-I dts -O dtb -p 2048" -f re-signing /kernel-exynos.its /tmp/exynos-kernel
340+ mkimage -D "-I dts -O dtb -p 2048" -f reflash /kernel-exynos.its /tmp/exynos-kernel
346341
347- vbutil_kernel --arch arm --pack kernel.bin --keyblock re-signing/kernel.keyblock --signprivate re-signing/kernel_data_key.vbprivk --version 1 --config re-signing/cmdline --bootloader re-signing/bootloader.bin --vmlinuz /tmp/exynos-kernel
348- ' > krn_re-signing
349- chmod +x krn_re-signing
350- ./krn_re-signing
342+ vbutil_kernel --arch arm --pack kernel_image --keyblock reflash/kernel.keyblock --signprivate reflash/kernel_data_key.vbprivk --version 1 --config reflash/cmdline --bootloader reflash/bootloader.bin --vmlinuz /tmp/exynos-kernel
351343
352- cp -f kernel.bin ${basedir} /kernel.bin
344+ rm -f reflash/kernel-exynos.its reflash/cmdline reflash/bootloader.bin
345+ ' > reflash/kernel_install
346+ chmod +x reflash/kernel_install
347+ reflash/kernel_install
353348
354- echo ' Package: linux-kernel-xe303c12
355- Version: ' " $kernver " '
356- Architecture: ' " $architecture " '
357- Maintainer: Kernel build script maintainer https://git[la,hu]b.com/quarkscript
358- Description: Custom ' " $architecture " ' linux kernel, builded for XE303C12 Chromebook
359- Depends: ' " $depends " '
360- Replaces: ' " $replaces " '
361- Provides: ' " $provides " '
362- Suggests: ' " $suggests " '
363- ' > ${basedir} /kernel_pkg/DEBIAN/control
349+ echo ' #!/bin/bash
350+ if [ "$(whoami)" == "root" ]; then
364351
365- echo ' #!/bin/bash
366- krnprts=""
367- krnprtc=0
352+ # resign kernel
353+
354+ echo "
355+ You may re-sign kernel and customize kernel boot string.
356+ Regular user do not need it, so it is safe to press n.
357+ Do you want to do this? (y/N)"
358+ read -r tmpvar1
359+ if $(echo $tmpvar1 | grep -q [Yy]); then
360+ bootcmd=' " 'console=tty0 root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd zswap.compressor=zstd zswap.max_pool_percent=40 audit=0'" '
361+ echo "
362+ default bootcmd is
363+
364+ $bootcmd
365+
366+ Be very careful, without root=PARTUUID=%U/PARTNROFF=1
367+ or something like that your could get a bootfail.
368+ Now you may specify a new one or just press Enter
369+ "
370+ tmpvar2=""
371+ read -r tmpvar2
372+ if [ ! -z "$tmpvar2" ]; then
373+ bootcmd="$tmpvar2"
374+ else
375+ echo " Will be used default boot string
376+ "
377+ fi
378+
379+ # make kernel.its
380+ echo ' " '" '
381+ /dts-v1/;
382+ / {
383+ description = "Chrome OS kernel image with one or more FDT blobs";
384+ #address-cells = <1>;
385+ images {
386+ kernel@1 {
387+ description = "kernel";
388+ data = /incbin/("/boot/zImage");
389+ type = "kernel_noload";
390+ arch = "arm";
391+ os = "linux";
392+ compression = "none";
393+ load = <0>;
394+ entry = <0>;
395+ };
396+ fdt@1 {
397+ description = "exynos5250-snow.dtb";
398+ data = /incbin/("/boot/dtbs/exynos5250-snow.dtb");
399+ type = "flat_dt";
400+ arch = "arm";
401+ compression = "none";
402+ hash@1 {
403+ algo = "sha1";
404+ };
405+ };
406+ fdt@2 {
407+ description = "exynos5250-snow-rev5.dtb";
408+ data = /incbin/("/boot/dtbs/exynos5250-snow-rev5.dtb");
409+ type = "flat_dt";
410+ arch = "arm";
411+ compression = "none";
412+ hash@1 {
413+ algo = "sha1";
414+ };
415+ };
416+ };
417+ configurations {
418+ default = "conf@1";
419+ conf@1 {
420+ kernel = "kernel@1";
421+ fdt = "fdt@1";
422+ };
423+ conf@2 {
424+ kernel = "kernel@1";
425+ fdt = "fdt@2";
426+ };
427+ };
428+ };
429+ ' " '" ' > /tmp/kernel.its
430+
431+ #
432+ mkimage -D "-I dts -O dtb -p 2048" -f /tmp/kernel.its /tmp/vmlinux.uimg
433+
434+ # make empty bootloader
435+ dd if=/dev/zero of=/tmp/bootloader.bin bs=512 count=1
436+
437+ echo $bootcmd > /tmp/cmdline
438+
439+ if [ -f /boot/kernel_image ]; then
440+ echo backing up existed image
441+ mv -f /boot/kernel_image /boot/backup_kernel_image
442+ echo you may restore it from backup_kernel_image
443+ fi
444+
445+ # final step
446+ vbutil_kernel \
447+ --pack /boot/kernel_image \
448+ --version 1 \
449+ --vmlinuz /tmp/vmlinux.uimg \
450+ --arch arm \
451+ --keyblock /boot/reflash/kernel.keyblock \
452+ --signprivate /boot/reflash/kernel_data_key.vbprivk \
453+ --config /tmp/cmdline \
454+ --bootloader /tmp/bootloader.bin
455+
456+ # clear used files
457+ rm -f /tmp/vmlinux.uimg /tmp/cmdline /tmp/bootloader.bin
458+ fi
459+
460+ # flash kernel
461+
462+ krnprts=""
463+ krnprtc=0
368464 for i in $(ls /dev | grep -x --regexp="mmcblk[0-9]" --regexp="sd[a-z]" --regexp="vd[a-z]"); do
369465 if $(cgpt show /dev/$i | grep Label | grep -q [Kk]ernel); then
370466 if $(echo $i | grep -q mmcblk); then
@@ -379,42 +475,93 @@ krnprtc=0
379475 echo ""
380476 if [ "$krnprtc" -eq 0 ]; then
381477 echo "Chrome OS kernel partition did not detected."
382- echo "You must reflash kernel manually."
478+ echo " You may need to flash kernel_image manually."
383479 elif [ "$krnprtc" -eq 1 ]; then
384- echo "Finded ChromeOs kernel partition - $krnprts"
385- echo "Do you want to flash a new kernel to it? (y/n)"
480+ if $(echo $krnprts | grep -q mmcblk0); then
481+ pr_part_type="# usually internal MMC"
482+ elif $(echo $krnprts | grep -q mmcblk1); then
483+ pr_part_type="# usually SD-card"
484+ elif $(echo $krnprts | grep -q sd); then
485+ pr_part_type="# usually USB-disk"
486+ else
487+ pr_part_type="# unknown disk type"
488+ fi
489+ echo "Finded ChromeOs kernel partition - $krnprts $pr_part_type"
490+ echo " Do you want to flash a new kernel to it? (y/N)"
386491 read -r shouldwe
387492 if [[ $shouldwe =~ ^([yY][eE][sS]|[yY])$ ]]; then
388- dd if=/boot/kernel.bin of=/dev/$krnprts
493+ echo make kernel partition backup to /boot/krn_pt_bk.gz
494+ dd if=/dev/$krnprts | gzip --best > /boot/krn_pt_bk.gz
495+ echo flash kernel
496+ dd if=/boot/kernel_image of=/dev/$krnprts
389497 sync
390498 else
391499 echo "You may flash kernel manually like:"
392- echo "dd if=/boot/kernel.bin of=/dev/$krnprts"
500+ echo "dd if=/boot/kernel_image of=/dev/$krnprts"
393501 fi
394502 else
395503 echo "Finded more than one Chrome OS kernel partition."
396- echo "You need to select next action
397- "
398- echo "0 for do not flash"
504+ echo "Current root is /dev/$(mount | grep " / " | sed "s/.*dev\///g" | sed "s/ .*//g")"
505+ echo "You need to specify next action "
506+ echo " 0 for do not flash"
399507 numpart=0
400508 for i in $krnprts; do
401509 numpart=$(($numpart+1))
402- echo "$numpart for flash $i partition"
510+ if $(echo $i | grep -q mmcblk0); then
511+ pr_part_type="# usually internal MMC"
512+ elif $(echo $i | grep -q mmcblk1); then
513+ pr_part_type="# usually SD-card"
514+ elif $(echo $i | grep -q sd); then
515+ pr_part_type="# usually USB-disk"
516+ else
517+ pr_part_type="# unknown disk type"
518+ fi
519+ echo " $numpart for flash $i partition $pr_part_type"
403520 done
404- echo ""
521+ # echo ""
405522 echo "Wrong partition may lead to bootfail. Be aware!"
406523 read -r shouldwe
407524 if [ $shouldwe -gt 0 ]&&[ $shouldwe -le $numpart ]; then
408525 numpart=0
409526 for i in $krnprts; do
410527 numpart=$(($numpart+1))
411528 if [ $numpart -eq $shouldwe ]; then
412- dd if=/boot/kernel.bin of=/dev/$i
529+ echo make kernel partition backup to /boot/krn_pt_bk.gz
530+ dd if=/dev/$i | gzip --best > /boot/krn_pt_bk.gz
531+ echo flash kernel
532+ dd if=/boot/kernel_image of=/dev/$i
413533 sync
414534 fi
415535 done
536+ else
537+ echo " Ok, you may flash kernel manually"
416538 fi
417539 fi
540+ else
541+ echo superuser rights required
542+ fi
543+ ' > reflash/kernel_install
544+
545+ cp -f kernel_image ${basedir} /kernel_image
546+
547+ echo ' Package: linux-kernel-xe303c12
548+ Version: ' " $kernver " '
549+ Architecture: ' " $architecture " '
550+ Maintainer: Kernel build script maintainer https://git[la,hu]b.com/quarkscript
551+ Description: Custom ' " $architecture " ' linux kernel, builded for XE303C12 Chromebook
552+ Depends: ' " $depends " '
553+ Replaces: ' " $replaces " '
554+ Provides: ' " $provides " '
555+ Suggests: ' " $suggests " '
556+ ' > ${basedir} /kernel_pkg/DEBIAN/control
557+
558+ echo ' #!/bin/bash
559+ /boot/reflash/kernel_install
560+
561+ echo "
562+ To repeat this operations run:
563+ sudo /boot/reflash/kernel_install
564+ "
418565' > ${basedir} /kernel_pkg/DEBIAN/postinst
419566 chmod 0755 ${basedir} /kernel_pkg/DEBIAN/postinst
420567 cd ${basedir} /
834981
835982 # Unmount partitions
836983 umount $rootp
837- if [ -f "${basedir} /kernel.bin " ]; then
838- dd if=${basedir} /kernel.bin of=$bootp
984+ if [ -f "${basedir} /kernel_image " ]; then
985+ dd if=${basedir} /kernel_image of=$bootp
839986 else
840987 echo '
841988Kernel flash image not found. Linux disk image may be unbootable
0 commit comments