如何检查u-boot脚本中是否存在文件?

时间:2021-08-06 12:15:08

I would like, from my u-boot script, to check the existence of a file on a device before running the image on this device. Indeed, this would ensure to have access to the requested device before booting from it. How could I test the file existence using u-boot console commands?

我想从我的u-boot脚本中检查设备上是否存在文件,然后再在此设备上运行图像。实际上,这将确保在从其启动之前访问所请求的设备。如何使用u-boot控制台命令测试文件是否存在?

The following test does a ls on the USB stick, and here are the results with USB stick present:

以下测试对USB记忆棒进行了测试,以下是USB记忆棒的结果:

> if ext2ls usb 0; then echo "USB ON"; else echo "USB KO"; fi
    <DIR>       4096 .
    <DIR>       4096 ..
    <DIR>      16384 lost+found
    <DIR>       4096 boot
                4096 boot.scr
USB ON

Same test without USB stick:

没有USB棒的相同测试:

> if ext2ls usb 0; then echo "USB ON"; else echo "USB KO"; fi
** Bad device usb 0 **
USB KO

My wish would be to test the presence of the boot.scr file in fact. How could I do that please?

我希望实际上是测试boot.scr文件的存在。我怎么能这样做?

1 个解决方案

#1


5  

You're fairly close. Since ext2ls (or the generic ls) only work on directories you instead need to do:

你离我很近。由于ext2ls(或通用ls)仅适用于您需要执行的目录:

=> if load mmc 0:1 ${loadaddr} notfound; then echo found; else echo notfound;fi
** File not found notfound **
=> if load mmc 0:1 ${loadaddr} boot.scr; then echo found; else echo notfound;fi
27980 bytes read in 26 ms (1 MiB/s)
found

You can see more examples of this kind of test and fall back in include/config_distro_bootcmd.h

您可以在include / config_distro_bootcmd.h中看到更多此类测试的示例

#1


5  

You're fairly close. Since ext2ls (or the generic ls) only work on directories you instead need to do:

你离我很近。由于ext2ls(或通用ls)仅适用于您需要执行的目录:

=> if load mmc 0:1 ${loadaddr} notfound; then echo found; else echo notfound;fi
** File not found notfound **
=> if load mmc 0:1 ${loadaddr} boot.scr; then echo found; else echo notfound;fi
27980 bytes read in 26 ms (1 MiB/s)
found

You can see more examples of this kind of test and fall back in include/config_distro_bootcmd.h

您可以在include / config_distro_bootcmd.h中看到更多此类测试的示例