Package: release.debian.org Severity: normal Tags: jessie User: release.debian....@packages.debian.org Usertags: pu
Hello, I'd like to update flash-kernel in jessie with the below debdiff. The intention is to fix the critical bug #813995. The two other changes are just prerequisites for it. These changes are in unstable since flash-kernel 3.59. The problem is that if the flash device that kernel/initramfs is written to is NAND flash, the handling implemented in flash-kernel is wrong. It works iff the flash doesn't have bad block. But if there is a bad block and it is written to, this can damage even otherwise good parts of the flash and so for example destroy the bootloader bricking the machine. Among the machines that flash-kernel officially supports (in jessie) there is only a single one affected (i.e. D-Link DNS-320 NAS (Rev A1)), but flash-kernel is easily extendable to support more machines, so I expect more machines to be affected. (I have a Netgear ReadyNAS 104 that uses NAND, it's little brother Netgear ReadyNAS 102 does, too.) The change by Karsten Merker is needed to keep the test suite (which is run during package build) happy. I admit this is not minimal (I could simply skip the test), but it seems to me as the most sensible change and this makes the change match the version of flash-kernel in testing/unstable. Ian Campbell's change is also necessary for NAND because nandwrite needs to operate on the character device. (One could argue that we should keep writing to mtdblock for NOR, but I don't think this is sensible.) Best regards Uwe diff -Nru flash-kernel-3.35+deb8u2/debian/changelog flash-kernel-3.35+deb8u3/debian/changelog --- flash-kernel-3.35+deb8u2/debian/changelog 2015-12-05 19:16:35.000000000 +0100 +++ flash-kernel-3.35+deb8u3/debian/changelog 2016-03-10 20:30:19.000000000 +0100 @@ -1,3 +1,19 @@ +flash-kernel (3.35+deb8u3) stable; urgency=medium + + [ Karsten Merker ] + * Disable the use of modprobe and udevadm in the mtdblock() function + while running the testsuite. + + [ Ian Campbell ] + * Use /dev/mtdN when flashing, rather than needlessly going through the + mtdblock layer (which is problematic on some platforms/kernels). + (Closes: #794265) + + [ Uwe Kleine-König ] + * use nandwrite when writing to nand flash. (Closes: #813995) + + -- Uwe Kleine-König <uklei...@debian.org> Thu, 10 Mar 2016 20:30:19 +0100 + flash-kernel (3.35+deb8u2) stable; urgency=medium [ Ian Campbell ] diff -Nru flash-kernel-3.35+deb8u2/debian/control flash-kernel-3.35+deb8u3/debian/control --- flash-kernel-3.35+deb8u2/debian/control 2015-11-10 11:14:39.000000000 +0100 +++ flash-kernel-3.35+deb8u3/debian/control 2016-03-10 20:28:57.000000000 +0100 @@ -17,6 +17,7 @@ devio, initramfs-tools (>= 0.92f), linux-base (>= 3.2), + mtd-utils, ucf Recommends: u-boot-tools Description: utility to make certain embedded devices bootable diff -Nru flash-kernel-3.35+deb8u2/functions flash-kernel-3.35+deb8u3/functions --- flash-kernel-3.35+deb8u2/functions 2015-11-10 11:14:39.000000000 +0100 +++ flash-kernel-3.35+deb8u3/functions 2016-03-10 20:29:41.000000000 +0100 @@ -43,7 +43,21 @@ local dev=`sed -rn "s,^mtd([^:]*).*\"$mtdname\"\$,/dev/mtdblock\\1,p" "$PROC_MTD"` - modprobe -q mtdblock && udevadm settle --exit-if-exists=$dev || : + # The mtdblock() function gets also called by the testsuite during + # the package build; don't run modprobe and udevadm then. Invasive + # actions like loading modules and calling into udev should not + # happen at build time and they are not necessary for the testsuite. + if [ -z "${FK_TESTSUITE_RUNNING}" ]; then + modprobe -q mtdblock && udevadm settle --exit-if-exists=$dev || : + fi + + echo $dev +} + +mtdchar() { + local mtdname="$1" + + local dev=`sed -rn "s,^mtd([^:]*).*\"$mtdname\"\$,/dev/mtd\\1,p" "$PROC_MTD"` echo $dev } @@ -56,6 +70,14 @@ fi } +check_char_dev() { + local dev="$1" + + if [ ! -c "$dev" ]; then + error "$dev is not a character device" + fi +} + mtdsize() { local mtdname="$1" @@ -257,6 +279,42 @@ } >"$output" } +write_mtd() { + local input_file="$1" + local output_mtd="$2" + local base_mtd=$(basename $output_mtd) + local tmpfile + + if [ "x$input_file" = "x-" ] ; then + tmpfile=$(mktemp -t "$self.$base_mtd.XXXXXX") || error "Failed" + cat > $tmpfile + input_file="$tmpfile" + fi + + # Can't really flashcp to /dev/mtd<N> when testing + if [ -z "${FK_TESTSUITE_RUNNING}" ]; then + local flashtype=$(cat /sys/class/mtd/$base_mtd/type) + case "$flashtype" in + nand|mlc-nand) + flash_erase "$output_mtd" 0 0 + nandwrite -p "$output_mtd" "$input_file" + ;; + nor) + flashcp "$input_file" "$output_mtd" + ;; + *) + error "unsupported flash type" + ;; + esac + else + cp "$input_file" "$output_mtd" + fi + + if [ "$tmpfile" ] ; then + rm -f "$tmpfile" + fi +} + flash_kernel() { local input_file="$1" local output_mtd="$2" @@ -273,7 +331,8 @@ fi printf "Flashing kernel$use... " >&2 - gen_kernel "$input_file" "$output_mtd" "$machine_id" || error "failed." + gen_kernel "$input_file" "$tmpdir/flash_kernel.raw" "$machine_id" || error "failed." + write_mtd "$tmpdir/flash_kernel.raw" "$output_mtd" || error "failed." echo "done." >&2 } @@ -293,7 +352,7 @@ if [ "$pad" -gt 0 ]; then dd if=/dev/zero bs="$pad" count=1 2>/dev/null fi - } >"$output_mtd" || error "failed." + } | write_mtd "-" "$output_mtd" || error "failed." echo "done." >&2 } @@ -586,21 +645,21 @@ fi fi if [ -n "$mtd_kernel" ]; then - kmtd=$(mtdblock "$mtd_kernel") + kmtd=$(mtdchar "$mtd_kernel") if [ -z "$kmtd" ]; then error "Cannot find mtd partition '$mtd_kernel'" fi - check_block_dev "$kmtd" + check_char_dev "$kmtd" kmtdsize=$(mtdsize "$mtd_kernel") kreqsize=$kfilesize check_mtd_size "$mtd_kernel" $kreqsize $kmtdsize kernel fi if [ -n "$mtd_initrd" ]; then - imtd=$(mtdblock "$mtd_initrd") + imtd=$(mtdchar "$mtd_initrd") if [ -z "$imtd" ]; then error "Cannot find mtd partition '$mtd_initrd'" fi - check_block_dev "$imtd" + check_char_dev "$imtd" imtdsize=$(mtdsize "$mtd_initrd") ireqsize=$ifilesize # encapsulating in an U-Boot image grows the size by 64 bytes diff -Nru flash-kernel-3.35+deb8u2/test_functions flash-kernel-3.35+deb8u3/test_functions --- flash-kernel-3.35+deb8u2/test_functions 2015-11-10 11:14:39.000000000 +0100 +++ flash-kernel-3.35+deb8u3/test_functions 2016-03-10 20:28:57.000000000 +0100 @@ -17,6 +17,9 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, # USA. +# Let the function library know that it is called from the testsuite. +FK_TESTSUITE_RUNNING="yes" + . ./testlib functions="${FK_CHECKOUT:-$FK_DIR}/functions" @@ -54,6 +57,34 @@ } add_test test_mtdblock +test_mtdchar() { + get_tempfile + mock_proc_mtd="$last_tempfile" + cat >"$mock_proc_mtd" <<EOF +dev: size erasesize name +mtd0: 00580000 00020000 "root" +mtd1: 00100000 00020000 "kernel" +mtd2: 00160000 00020000 "initrd" +mtd3: 00020000 00020000 "reset" +mtd4: 00800000 00020000 "jffs2" +EOF + ( + . "$functions" + PROC_MTD="$mock_proc_mtd" + root_mtd=$(mtdchar "root") + if [ "$root_mtd" != "/dev/mtd0" ]; then + echo "Expected root mtd to be /dev/mtd0 but got $root_mtd" >&2 + exit 1 + fi + jffs2_mtd=$(mtdchar "jffs2") + if [ "$jffs2_mtd" != "/dev/mtd4" ]; then + echo "Expected jffs2 mtd to be /dev/mtd4 but got $jffs2_mtd" >&2 + exit 1 + fi + ) +} +add_test test_mtdchar + test_mtdsize() { get_tempfile mock_proc_mtd="$last_tempfile"