kdump: redirect stderr to the pstore message

This will output any error messages from makedumpfile to the pstore so
that we can view it after reboot.

Also this fixes the aspeed platforms kdump page missing.
Somehow makedumpfile could dump stderr output into the core. The reason is still unclear but might be due to stdout/err pts is not created properly yet in the init script env.

Tested: on a aspeed bmc, kcore is generated and crash can parse it with no issue.

Fusion-link: https://fusion2.corp.google.com/f02af0d3-5214-3bfd-957e-a1cbe5bd3ef9  https://fusion2.corp.google.com/c8998f37-72e7-3965-88f8-b6b6caa528d0

Google-Bug-Id: 370096566
Change-Id: I31c0a65baee45838414d3b040d7eb13f4bbbe536
Signed-off-by: Yuxiao Zhang <yuxiaozhang@google.com>
diff --git a/recipes-google/kdump-core/files/gbmc-kexec-init.sh b/recipes-google/kdump-core/files/gbmc-kexec-init.sh
index ebd8528..5923fb8 100644
--- a/recipes-google/kdump-core/files/gbmc-kexec-init.sh
+++ b/recipes-google/kdump-core/files/gbmc-kexec-init.sh
@@ -18,16 +18,16 @@
         echo 'core dump found'
         /makedumpfile --dump-dmesg /proc/vmcore /tmp/dmesg
 
+        # We have to process it for getting the size only, because
+        # we don't have spaces for saving the core file
+        core_size=$(/makedumpfile -F -c -d 31 /proc/vmcore 2>>/tmp/dmesg | wc -c)
+
         msg_len=$(cat /tmp/dmesg | wc -c)
 
         echo $msg_len > /dev/pmsg0
         cat /tmp/dmesg > /dev/pmsg0
         rm /tmp/dmesg
 
-        # We have to process it for getting the size only, because
-        # we don't have spaces for saving the core file
-        core_size=$(/makedumpfile -F -c -d 31 /proc/vmcore | wc -c)
-
         total_size=`expr $core_size + $msg_len`
         # 32 * 1024 * 1024 - 64, exclude the length size of the first line, and
         # a pmsg header for holding metadata.
@@ -36,7 +36,7 @@
         if [ "$total_size" -gt "$max_size" ]; then
                 echo "$ERROR_MSG: total size too large: core size $core_size, msg size $msg_len" > /dev/pmsg0
         else
-                /makedumpfile -F -c -d 31 /proc/vmcore > /dev/pmsg0
+                /makedumpfile -F -c -d 31 /proc/vmcore 2>/dev/null > /dev/pmsg0
         fi
 else
         dmesg='empty dmesg'