Hi,
I'm facing a new problem for my Mt7628/vocore2 target.
I moved the Linux kernel from a ext4 partition to the "proper" SquashFS
partition (I say "proper" because I'm using a dual-system with fallback to
avoid updating the currently working rootFS and kernel lies into rootFS).
I am using u-boot v2020.10-rc3 plus the attached patches (one pertains
SquashFS).
Problem is a real cold boot (target off for more than one minute) leads to a
load failure for the kernel. A warm boot ("reboot" from a running Linux) or a
not-so-cold boot (turn target off and power it on again after a few seconds)
seems to work as expected.
I tried to insert delays and/or "mmc rescan", but that does not seem to have
any effect.
Also error message is not always the same; sometimes I get:
Error: too many data blocks to be read.
Failed to load '/boot/uImage'
other times:
** fs_devread read error - block
Failed to mount ext2 filesystem...
** Unrecognized filesystem type **
My full environment is:
BOOT_CURRENT=A
SYSTEM_R=/dev/mtdblock5
arch=mips
baudrate=115200
board=vocore2
board_name=vocore2
boot_a=echo "Loading System A";part=6;run boot_x
boot_b=echo "Loading System B";part=7;run boot_x
boot_now=if test "${BOOT_CURRENT}" = A; then run boot_a; elif test
"${BOOT_CURRENT}" = B; then run boot_b; fi; if env exists BOOT_A_GOOD; then run
boot_a; fi; if env exists BOOT_B_GOOD; then run boot_b; fi; run boot_r
boot_r=echo "Loading Recovery"; setenv bootargs "${default_bootargs}
mtdparts=${mtdparts} root=/dev/mtdblock5"; bootm bc050000
boot_x=load mmc 0:${part} 85000000 /boot/uImage && setenv bootargs
"${default_bootargs} mtdparts=${mtdparts} root=/dev/mmcblk0p${part}" && bootm
${fileaddr}
bootcmd=run do_boot
bootcount=1
bootdelay=2
cpu=mips32
default_bootargs=earlyprintk rootwait console=ttyS2,115200
do_boot=test ${bootcount} -gt 1 && run remove_boot; run boot_now
fdtcontroladdr=86f6d340
fileaddr=84000000
filesize=154
fupdate=mmc rescan && load mmc 0:1 84000000 uboot.scr && fatrm mmc 0:1
uboot.scr && source 84000000 && echo Flash updated || Flash update FAILED!
mtdids=nor0=spi0.0
mtdparts=spi0.0:312k(u-boot),4k(env),4k(factory),2368k(kernel),-(filesystem)
remove_boot=if env exists BOOT_CURRENT; then setenv BOOT_CURRENT; saveenv;
elif env exists BOOT_A_GOOD; then setenv BOOT_A_GOOD; saveenv; elif env exists
BOOT_B_GOOD; then setenv BOOT_B_GOOD; saveenv; fi
soc=mt7628
stderr=uart2@e00
stdin=uart2@e00
stdout=uart2@e00
vendor=vocore
ver=U-Boot 2020.10-rc3 (Sep 16 2020 - 19:43:03 +0200)
It was suggested (on IRC) it could be a cache problem. unfortunately trying to
enable cache control (CONFIG_CMD_CACHE) raises error in compilation:
...
LD u-boot
/home/valeria/MyProject/VoCore/Buildroot-2/recov/per-package/uboot/host/bin/mipsel-linux-ld.bfd:
cmd/built-in.o: in function `do_icache':
cmd/cache.c:(.text.do_icache+0x5c): undefined reference to `icache_disable'
/home/valeria/MyProject/VoCore/Buildroot-2/recov/per-package/uboot/host/bin/mipsel-linux-ld.bfd:
cmd/cache.c:(.text.do_icache+0x6c): undefined reference to `icache_enable'
/home/valeria/MyProject/VoCore/Buildroot-2/recov/per-package/uboot/host/bin/mipsel-linux-ld.bfd:
cmd/cache.c:(.text.do_icache+0x8c): undefined reference to `icache_status'
Makefile:1753: recipe for target 'u-boot' failed
make[2]: *** [u-boot] Error 1
package/pkg-generic.mk:266 <http://pkg-generic.mk:266>: recipe for target
'/home/valeria/MyProject/VoCore/Buildroot-2/recov/build/uboot-v2020.10-rc3/.stamp_built'
failed
make[1]: ***
[/home/valeria/MyProject/VoCore/Buildroot-2/recov/build/uboot-v2020.10-rc3/.stamp_built]
Error 2
Makefile:23: recipe for target '_all' failed
make: *** [_all] Error 2
and I have no idea how to fix this.
Any hint would be very welcome as this is a real show-stopper for me.
Thanks in Advance
Mauro
From 4a9d0b3ce9fcfca9fcb987f26c51600fee66b4e3 Mon Sep 17 00:00:00 2001
From: Mauro Condarelli <[email protected]>
Date: Wed, 2 Sep 2020 16:04:40 +0200
Subject: [PATCH 1/4] Small fixes to reduce size and ensure correct console
output.
Signed-off-by: Mauro Condarelli <[email protected]>
---
arch/mips/dts/vocore_vocore2.dts | 2 +-
include/configs/vocore2.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/mips/dts/vocore_vocore2.dts b/arch/mips/dts/vocore_vocore2.dts
index 3502e4b8b7..9adf39652f 100644
--- a/arch/mips/dts/vocore_vocore2.dts
+++ b/arch/mips/dts/vocore_vocore2.dts
@@ -59,7 +59,7 @@
#address-cells = <1>;
#size-cells = <1>;
compatible = "jedec,spi-nor";
- spi-max-frequency = <25000000>;
+ spi-max-frequency = <40000000>;
reg = <0>;
};
};
diff --git a/include/configs/vocore2.h b/include/configs/vocore2.h
index 40467b737c..29a57ad233 100644
--- a/include/configs/vocore2.h
+++ b/include/configs/vocore2.h
@@ -25,6 +25,7 @@
#define CONFIG_SPL_BSS_START_ADDR 0x80010000
#define CONFIG_SPL_BSS_MAX_SIZE 0x10000
#define CONFIG_SPL_MAX_SIZE 0x10000
+#define CONFIG_SPL_PAD_TO 0
/* Dummy value */
#define CONFIG_SYS_UBOOT_BASE 0
@@ -34,6 +35,7 @@
#define CONFIG_SYS_NS16550_CLK 40000000
#define CONFIG_SYS_NS16550_REG_SIZE -4
#define CONFIG_SYS_NS16550_COM3 0xb0000e00
+#define CONFIG_CONS_INDEX 3
/* RAM */
--
2.25.1
From 11d9dd468b34afe6b99ccbc647b5673ee20197cd Mon Sep 17 00:00:00 2001
From: Mauro Condarelli <[email protected]>
Date: Wed, 2 Sep 2020 16:41:20 +0200
Subject: [PATCH 4/4] Project specific ENV initialization.
Signed-off-by: Mauro Condarelli <[email protected]>
---
include/configs/vocore2.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/configs/vocore2.h b/include/configs/vocore2.h
index dfdb8fcc04..ea8740720c 100644
--- a/include/configs/vocore2.h
+++ b/include/configs/vocore2.h
@@ -49,5 +49,19 @@
#define CONFIG_SYS_MONITOR_BASE CONFIG_SYS_TEXT_BASE
/* Environment settings */
+#define CONFIG_BOOTCOMMAND \
+ "run fupdate; run boot_r"
+#define CONFIG_EXTRA_ENV_SETTINGS \
+ "default_bootargs=earlyprintk rootwait console=ttyS2,115200\0" \
+ "mtdids=nor0=spi0.0\0" \
+ "mtdparts=spi0.0:312k(u-boot),4k(env),4k(factory),2368k(kernel),-(filesystem)\0" \
+ "fupdate=mmc rescan && load mmc 0:1 84000000 uboot.scr && fatrm mmc 0:1 uboot.scr && source 84000000 && echo Flash updated\0" \
+ "boot_a=echo \"Loading System A\";part=6;run boot_x\0" \
+ "boot_b=echo \"Loading System B\";part=7;run boot_x\0" \
+ "boot_x=load mmc 0:${part} 85000000 /boot/uImage && setenv bootargs \"${default_bootargs} mtdparts=${mtdparts} root=/dev/mmcblk0p${part}\" && bootm ${fileaddr}\0" \
+ "boot_r=echo \"Loading Recovery\"; setenv bootargs \"${default_bootargs} mtdparts=${mtdparts} root=/dev/mtdblock5\"; bootm bc050000\0" \
+ "remove_boot=if env exists BOOT_CURRENT; then setenv BOOT_CURRENT; saveenv; elif env exists BOOT_A_GOOD; then setenv BOOT_A_GOOD; saveenv; elif env exists BOOT_B_GOOD; then setenv BOOT_B_GOOD; saveenv; fi\0" \
+ "boot_now=if test \"${BOOT_CURRENT}\" = A; then run boot_a; elif test \"${BOOT_CURRENT}\" = B; then run boot_b; fi; if env exists BOOT_A_GOOD; then run boot_a; fi; if env exists BOOT_B_GOOD; then run boot_b; fi; run boot_r\0" \
+ "do_boot=test ${bootcount} -gt 1 && run remove_boot; run boot_now"
#endif //__VOCORE2_CONFIG_H__
--
2.25.1
From 4ebe2a580e572f79a6ac6c329b448f4bd64ee028 Mon Sep 17 00:00:00 2001
From: Mauro Condarelli <[email protected]>
Date: Thu, 3 Sep 2020 08:37:58 +0200
Subject: [PATCH 3/4] Fix missing __udivdi3 in SquashFS implementation.
Signed-off-by: Mauro Condarelli <[email protected]>
---
fs/squashfs/sqfs.c | 45 +++++++++++++++++++++++++--------------
fs/squashfs/sqfs_inode.c | 8 +++----
include/configs/vocore2.h | 2 +-
3 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index f67f7c4a40..b8dcc15eb8 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -18,6 +18,8 @@
#include <string.h>
#include <squashfs.h>
#include <part.h>
+#include <div64.h>
+#include <stdio.h>
#include "sqfs_decompressor.h"
#include "sqfs_filesystem.h"
@@ -82,13 +84,16 @@ static int sqfs_count_tokens(const char *filename)
*/
static int sqfs_calc_n_blks(__le64 start, __le64 end, u64 *offset)
{
- u64 start_, table_size;
+ u64 start_, table_size, blks;
table_size = le64_to_cpu(end) - le64_to_cpu(start);
- start_ = le64_to_cpu(start) / ctxt.cur_dev->blksz;
+ start_ = le64_to_cpu(start);
+ do_div(start_, ctxt.cur_dev->blksz);
*offset = le64_to_cpu(start) - (start_ * ctxt.cur_dev->blksz);
- return DIV_ROUND_UP(table_size + *offset, ctxt.cur_dev->blksz);
+ blks = table_size + *offset;
+ if (do_div(blks, ctxt.cur_dev->blksz)) blks++;
+ return blks;
}
/*
@@ -109,8 +114,8 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
if (inode_fragment_index >= get_unaligned_le32(&sblk->fragments))
return -EINVAL;
- start = get_unaligned_le64(&sblk->fragment_table_start) /
- ctxt.cur_dev->blksz;
+ start = get_unaligned_le64(&sblk->fragment_table_start);
+ do_div(start, ctxt.cur_dev->blksz);
n_blks = sqfs_calc_n_blks(sblk->fragment_table_start,
sblk->export_table_start,
&table_offset);
@@ -135,7 +140,8 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
start_block = get_unaligned_le64(table + table_offset + block *
sizeof(u64));
- start = start_block / ctxt.cur_dev->blksz;
+ start = start_block;
+ do_div(start, ctxt.cur_dev->blksz);
n_blks = sqfs_calc_n_blks(cpu_to_le64(start_block),
sblk->fragment_table_start, &table_offset);
@@ -641,8 +647,8 @@ static int sqfs_read_inode_table(unsigned char **inode_table)
table_size = get_unaligned_le64(&sblk->directory_table_start) -
get_unaligned_le64(&sblk->inode_table_start);
- start = get_unaligned_le64(&sblk->inode_table_start) /
- ctxt.cur_dev->blksz;
+ start = get_unaligned_le64(&sblk->inode_table_start);
+ do_div(start, ctxt.cur_dev->blksz);
n_blks = sqfs_calc_n_blks(sblk->inode_table_start,
sblk->directory_table_start, &table_offset);
@@ -725,8 +731,8 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list)
/* DIRECTORY TABLE */
table_size = get_unaligned_le64(&sblk->fragment_table_start) -
get_unaligned_le64(&sblk->directory_table_start);
- start = get_unaligned_le64(&sblk->directory_table_start) /
- ctxt.cur_dev->blksz;
+ start = get_unaligned_le64(&sblk->directory_table_start);
+ do_div(start, ctxt.cur_dev->blksz);
n_blks = sqfs_calc_n_blks(sblk->directory_table_start,
sblk->fragment_table_start, &table_offset);
@@ -1155,6 +1161,7 @@ static int sqfs_get_regfile_info(struct squashfs_reg_inode *reg,
fentry);
if (ret < 0)
return -EINVAL;
+
finfo->comp = true;
if (fentry->size < 1 || fentry->start < 0)
return -EINVAL;
@@ -1322,17 +1329,19 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
data_offset = finfo.start;
datablock = malloc(get_unaligned_le32(&sblk->block_size));
if (!datablock) {
+ printf("Error: malloc(%u) failed.\n", get_unaligned_le32(&sblk->block_size));
ret = -ENOMEM;
goto free_paths;
}
}
for (j = 0; j < datablk_count; j++) {
- start = data_offset / ctxt.cur_dev->blksz;
+ start = data_offset;
+ do_div(start, ctxt.cur_dev->blksz);
table_size = SQFS_BLOCK_SIZE(finfo.blk_sizes[j]);
table_offset = data_offset - (start * ctxt.cur_dev->blksz);
- n_blks = DIV_ROUND_UP(table_size + table_offset,
- ctxt.cur_dev->blksz);
+ n_blks = table_size + table_offset;
+ if (do_div(n_blks, ctxt.cur_dev->blksz)) n_blks++;
data_buffer = malloc_cache_aligned(n_blks * ctxt.cur_dev->blksz);
@@ -1359,8 +1368,10 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
dest_len = get_unaligned_le32(&sblk->block_size);
ret = sqfs_decompress(&ctxt, datablock, &dest_len,
data, table_size);
- if (ret)
+ if (ret) {
+ printf("Errrt: block decompress failed.\n");
goto free_buffer;
+ }
memcpy(buf + offset + *actread, datablock, dest_len);
*actread += dest_len;
@@ -1382,10 +1393,12 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
goto free_buffer;
}
- start = frag_entry.start / ctxt.cur_dev->blksz;
+ start = frag_entry.start;
+ do_div(start, ctxt.cur_dev->blksz);
table_size = SQFS_BLOCK_SIZE(frag_entry.size);
table_offset = frag_entry.start - (start * ctxt.cur_dev->blksz);
- n_blks = DIV_ROUND_UP(table_size + table_offset, ctxt.cur_dev->blksz);
+ n_blks = table_size + table_offset;
+ if (do_div(n_blks, ctxt.cur_dev->blksz)) n_blks++;
fragment = malloc_cache_aligned(n_blks * ctxt.cur_dev->blksz);
diff --git a/fs/squashfs/sqfs_inode.c b/fs/squashfs/sqfs_inode.c
index 1387779a85..f0e916e6a3 100644
--- a/fs/squashfs/sqfs_inode.c
+++ b/fs/squashfs/sqfs_inode.c
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <div64.h>
#include "sqfs_decompressor.h"
#include "sqfs_filesystem.h"
@@ -67,10 +68,9 @@ int sqfs_inode_size(struct squashfs_base_inode *inode, u32 blk_size)
u64 file_size = get_unaligned_le64(&lreg->file_size);
unsigned int blk_list_size;
- if (fragment == 0xFFFFFFFF)
- blk_list_size = DIV_ROUND_UP(file_size, blk_size);
- else
- blk_list_size = file_size / blk_size;
+ if (do_div(file_size, blk_size) && (fragment == 0xFFFFFFFF))
+ file_size++;
+ blk_list_size = file_size;
return sizeof(*lreg) + blk_list_size * sizeof(u32);
}
diff --git a/include/configs/vocore2.h b/include/configs/vocore2.h
index 29a57ad233..dfdb8fcc04 100644
--- a/include/configs/vocore2.h
+++ b/include/configs/vocore2.h
@@ -41,7 +41,7 @@
/* Memory usage */
#define CONFIG_SYS_MAXARGS 64
-#define CONFIG_SYS_MALLOC_LEN (1024 * 1024)
+#define CONFIG_SYS_MALLOC_LEN (16 * 1024 * 1024)
#define CONFIG_SYS_BOOTPARAMS_LEN (128 * 1024)
#define CONFIG_SYS_CBSIZE 512
--
2.25.1
From 1877771a95e130565d5d9c9fbaadea0673b38a0d Mon Sep 17 00:00:00 2001
From: Mauro Condarelli <[email protected]>
Date: Wed, 2 Sep 2020 16:08:54 +0200
Subject: [PATCH 2/4] Enlarge SPL malloc area to prevent failure in lzma
decompression.
Signed-off-by: Mauro Condarelli <[email protected]>
---
configs/vocore2_defconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configs/vocore2_defconfig b/configs/vocore2_defconfig
index 99a1143e6e..5776aada15 100644
--- a/configs/vocore2_defconfig
+++ b/configs/vocore2_defconfig
@@ -6,7 +6,7 @@ CONFIG_ENV_SIZE=0x1000
CONFIG_ENV_OFFSET=0x04e000
CONFIG_ENV_SECT_SIZE=0x1000
CONFIG_SYS_BOOTCOUNT_ADDR=0xb000006c
-CONFIG_SPL_SYS_MALLOC_F_LEN=0x20000
+CONFIG_SPL_SYS_MALLOC_F_LEN=0x40000
CONFIG_SPL=y
CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
CONFIG_ARCH_MTMIPS=y
--
2.25.1