From 65dc3d972e8281fd8625ffd37b2e67994557f88d Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Fri, 02 Aug 2019 18:50:48 +0800
Subject: [PATCH] update rootfs build shell script, fix ubifs rootfs running bug

---
 ok335xD/3rdparty/openssl/build.sh |    5 ++++-
 ok335xD/linux-bsp/build.sh        |   41 ++++++++++++++++++++++++++++-------------
 2 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/ok335xD/3rdparty/openssl/build.sh b/ok335xD/3rdparty/openssl/build.sh
index 4e79f5c..123eb10 100755
--- a/ok335xD/3rdparty/openssl/build.sh
+++ b/ok335xD/3rdparty/openssl/build.sh
@@ -9,6 +9,8 @@
 
 PREFIX_PATH=`pwd`/../install
 
+LYFTP_SRC=ftp://master.iot-yun.club/src/
+
 if [ -z $CROSSTOOL ] ; then
    CROSSTOOL=/opt/crosstool/cortex-a7/bin/arm-linux-gnueabi-
 fi
@@ -65,7 +67,8 @@
     
     msg_banner "Start cross compile $SRC_NAME " 
     if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then 
-        wget https://www.openssl.org/source/${SRC_NAME}.${PACK_SUFIX} 
+        #wget https://www.openssl.org/source/${SRC_NAME}.${PACK_SUFIX} 
+        wget ${LYFTP_SRC}/${SRC_NAME}.${PACK_SUFIX}
         check_result "ERROR: download ${SRC_NAME} failure"
     fi  
 
diff --git a/ok335xD/linux-bsp/build.sh b/ok335xD/linux-bsp/build.sh
index eb02384..d9f2a77 100755
--- a/ok335xD/linux-bsp/build.sh
+++ b/ok335xD/linux-bsp/build.sh
@@ -113,22 +113,37 @@
 	cd -
 }
 
+#/tmp >: ubiattach -m 5 -d 5 /dev/ubi_ctrl
+#[  822.268210] UBI: attaching mtd5 to ubi5
+#[  822.272237] UBI: physical eraseblock size:   131072 bytes (128 KiB)
+#[  822.278848] UBI: logical eraseblock size:    126976 bytes
+#[  822.284479] UBI: smallest flash I/O unit:    2048
+#[  822.289398] UBI: VID header offset:          2048 (aligned 2048)
+#[  822.295665] UBI: data offset:                4096
+
 function build_ubifs()
 {
-    mkfs.ubifs –F -q -r ${ROOTFS_SRC} -m 2048 -e 126976 -c 2047 -o ubi.img
-    cat > ubinize.cfg <<EOF
-[ubifs]
-mode=ubi
-image=ubi.img
-vol_id=0
-vol_size=140MiB
-vol_type=dynamic
-vol_name=rootfs
-vol_flags=autoresize
-EOF
+    ubinize_cfg=ubinize.cfg 
+    ubimg_tmp=ubi.img
 
-    ubinize -o ${ROOTFS_IMG} -m 2048 -p 128KiB ubinize.cfg
-    rm -f ubi.img  ubinize.cfg
+    partition_size=140  # MiB 
+
+    # PEB counter: PartitionSize / PagesPerBlock(64) / PageSize(2K)
+    partition_peb_cnt=`expr $partition_size \* 1024 / 64 / 2`
+
+    # LEB counter need reserved some blocks for UBI badblock used.
+    partition_leb_cnt=`expr $partition_peb_cnt - 20`
+
+    echo "Parition size ${partition_size}MiB set LEB=$partition_leb_cnt"
+    set -x
+    mkfs.ubifs -F -d ${ROOTFS_SRC} -m 2048 -e 126976 -c $partition_leb_cnt -o ubi.img
+    set +x
+
+    printf "[ubifs] \nmode=ubi \nimage=${ubimg_tmp} \nvol_id=0 \nvol_size=${partition_size}MiB\n" > $ubinize_cfg 
+    printf "vol_type=dynamic \nvol_name=rootfs \nvol_flags=autoresize\n" >> $ubinize_cfg
+
+    ubinize -o ${ROOTFS_IMG} -m 2048 -p 128KiB $ubinize_cfg
+    rm -f $ubimg_tmp $ubinize_cfg
 
     chmod a+x ${ROOTFS_IMG}
 }

--
Gitblit v1.9.1