From 15ac366e7d03bd75dfc19a14671e36f89f756925 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Sun, 8 Sep 2024 17:15:26 +0800 Subject: [PATCH] uboot: failsafe: support boot into initramfs sort uri handlers while at it. Signed-off-by: Tianling Shen --- uboot-mtk-20220606/failsafe/failsafe.c | 45 ++++++++++++----- .../failsafe/fsdata/booting.html | 49 +++++++++++++++++++ .../failsafe/fsdata/initramfs.html | 39 +++++++++++++++ .../failsafe/failsafe.c | 37 ++++++++++---- .../failsafe/fsdata/Makefile | 48 ++++++++++-------- .../failsafe/fsdata/booting.html | 39 +++++++++++++++ .../failsafe/fsdata/initramfs.html | 39 +++++++++++++++ .../include/failsafe/fw_type.h | 1 + 8 files changed, 255 insertions(+), 42 deletions(-) create mode 100644 uboot-mtk-20220606/failsafe/fsdata/booting.html create mode 100644 uboot-mtk-20220606/failsafe/fsdata/initramfs.html create mode 100644 uboot-mtk-20230718-09eda825/failsafe/fsdata/booting.html create mode 100644 uboot-mtk-20230718-09eda825/failsafe/fsdata/initramfs.html diff --git a/uboot-mtk-20220606/failsafe/failsafe.c b/uboot-mtk-20220606/failsafe/failsafe.c index f3dfacfcc..1cb4311d7 100644 --- a/uboot-mtk-20220606/failsafe/failsafe.c +++ b/uboot-mtk-20220606/failsafe/failsafe.c @@ -19,6 +19,7 @@ #include #include +#include "../board/mediatek/common/boot_helper.h" #include "fs.h" void led_control(const char *cmd, const char *name, const char *arg); @@ -27,7 +28,8 @@ enum { FW_TYPE_GPT, FW_TYPE_BL2, FW_TYPE_FIP, - FW_TYPE_FW + FW_TYPE_FW, + FW_TYPE_INITRD }; typedef struct fip_toc_header { @@ -276,6 +278,14 @@ static void upload_handler(enum httpd_uri_handler_status status, goto done; } + fw = httpd_request_find_value(request, "initramfs"); + if (fw) { + fw_type = FW_TYPE_INITRD; + if (fdt_check_header(fw->data)) + goto fail; + goto done; + } + fw = httpd_request_find_value(request, "firmware"); if (fw) { fw_type = FW_TYPE_FW; @@ -377,8 +387,11 @@ static void result_handler(enum httpd_uri_handler_status status, env_save(); } #endif - st->ret = write_firmware_failsafe((size_t) upload_data, - upload_size); + if (fw_type == FW_TYPE_INITRD) + st->ret = 0; + else + st->ret = write_firmware_failsafe((size_t) upload_data, + upload_size); } /* invalidate upload identifier */ @@ -444,21 +457,23 @@ int start_web_failsafe(void) } httpd_register_uri_handler(inst, "/", &index_handler, NULL); + httpd_register_uri_handler(inst, "/bl2.html", &html_handler, NULL); + httpd_register_uri_handler(inst, "/booting.html", &html_handler, NULL); httpd_register_uri_handler(inst, "/cgi-bin/luci", &index_handler, NULL); httpd_register_uri_handler(inst, "/cgi-bin/luci/", &index_handler, NULL); + httpd_register_uri_handler(inst, "/fail.html", &html_handler, NULL); + httpd_register_uri_handler(inst, "/flashing.html", &html_handler, NULL); + httpd_register_uri_handler(inst, "/getmtdlayout", &mtd_layout_handler, NULL); #if defined(CONFIG_MT7981_BOOTMENU_EMMC) || defined(CONFIG_MT7986_BOOTMENU_EMMC) httpd_register_uri_handler(inst, "/gpt.html", &html_handler, NULL); #endif - httpd_register_uri_handler(inst, "/bl2.html", &html_handler, NULL); - httpd_register_uri_handler(inst, "/uboot.html", &html_handler, NULL); - httpd_register_uri_handler(inst, "/fail.html", &html_handler, NULL); - httpd_register_uri_handler(inst, "/flashing.html", &html_handler, NULL); - httpd_register_uri_handler(inst, "/version", &version_handler, NULL); - httpd_register_uri_handler(inst, "/getmtdlayout", &mtd_layout_handler, NULL); - httpd_register_uri_handler(inst, "/upload", &upload_handler, NULL); + httpd_register_uri_handler(inst, "/index.js", &js_handler, NULL); + httpd_register_uri_handler(inst, "/initramfs.html", &html_handler, NULL); httpd_register_uri_handler(inst, "/result", &result_handler, NULL); httpd_register_uri_handler(inst, "/style.css", &style_handler, NULL); - httpd_register_uri_handler(inst, "/index.js", &js_handler, NULL); + httpd_register_uri_handler(inst, "/uboot.html", &html_handler, NULL); + httpd_register_uri_handler(inst, "/upload", &upload_handler, NULL); + httpd_register_uri_handler(inst, "/version", &version_handler, NULL); httpd_register_uri_handler(inst, "", ¬_found_handler, NULL); net_loop(TCP); @@ -486,8 +501,12 @@ static int do_httpd(struct cmd_tbl *cmdtp, int flag, int argc, ret = start_web_failsafe(); - if (upgrade_success) - do_reset(NULL, 0, 0, NULL); + if (upgrade_success) { + if (fw_type == FW_TYPE_INITRD) + boot_from_mem((ulong)upload_data); + else + do_reset(NULL, 0, 0, NULL); + } return ret; } diff --git a/uboot-mtk-20220606/failsafe/fsdata/booting.html b/uboot-mtk-20220606/failsafe/fsdata/booting.html new file mode 100644 index 000000000..190d17387 --- /dev/null +++ b/uboot-mtk-20220606/failsafe/fsdata/booting.html @@ -0,0 +1,49 @@ + + + + + Booting initramfs + + + + + +
+

BOOTING INITRAMFS

+

+ Your file was successfully uploaded! Booting is in progress, please wait...
+ This page may be in not responding status for a short time. +

+
+
+
+ + diff --git a/uboot-mtk-20220606/failsafe/fsdata/initramfs.html b/uboot-mtk-20220606/failsafe/fsdata/initramfs.html new file mode 100644 index 000000000..c23479d2c --- /dev/null +++ b/uboot-mtk-20220606/failsafe/fsdata/initramfs.html @@ -0,0 +1,39 @@ + + + + + Load initramfs + + + + +
+

LOAD INITRAMFS

+

+ You are going to load initramfs on the device.
+ Please, choose file from your local hard drive and click Upload button. +

+
+ + +
+
+ +
+ + + +
+ WARNINGS +
    +
  • if everything goes well, the device will boot into the initramfs
  • +
  • you can upload whatever you want, so be sure that you choose proper initramfs image for your device
  • +
+
+
+
+ + diff --git a/uboot-mtk-20230718-09eda825/failsafe/failsafe.c b/uboot-mtk-20230718-09eda825/failsafe/failsafe.c index daced91d9..61aba9f5f 100644 --- a/uboot-mtk-20230718-09eda825/failsafe/failsafe.c +++ b/uboot-mtk-20230718-09eda825/failsafe/failsafe.c @@ -20,6 +20,8 @@ #include #include #include + +#include "../board/mediatek/common/boot_helper.h" #include "fs.h" static u32 upload_data_id; @@ -154,6 +156,14 @@ static void upload_handler(enum httpd_uri_handler_status status, goto done; } + fw = httpd_request_find_value(request, "initramfs"); + if (fw) { + fw_type = FW_TYPE_INITRD; + if (fdt_check_header(fw->data)) + goto fail; + goto done; + } + fail: response->data = "fail"; response->size = strlen(response->data); @@ -248,8 +258,11 @@ static void result_handler(enum httpd_uri_handler_status status, env_save(); } #endif - st->ret = failsafe_write_image(upload_data, - upload_size, fw_type); + if (fw_type == FW_TYPE_INITRD) + st->ret = 0; + else + st->ret = failsafe_write_image(upload_data, + upload_size, fw_type); } /* invalidate upload identifier */ @@ -377,21 +390,23 @@ int start_web_failsafe(void) } httpd_register_uri_handler(inst, "/", &index_handler, NULL); + httpd_register_uri_handler(inst, "/bl2.html", &html_handler, NULL); + httpd_register_uri_handler(inst, "/booting.html", &html_handler, NULL); httpd_register_uri_handler(inst, "/cgi-bin/luci", &index_handler, NULL); httpd_register_uri_handler(inst, "/cgi-bin/luci/", &index_handler, NULL); - httpd_register_uri_handler(inst, "/upload", &upload_handler, NULL); httpd_register_uri_handler(inst, "/fail.html", &html_handler, NULL); httpd_register_uri_handler(inst, "/flashing.html", &html_handler, NULL); - httpd_register_uri_handler(inst, "/uboot.html", &html_handler, NULL); - httpd_register_uri_handler(inst, "/bl2.html", &html_handler, NULL); httpd_register_uri_handler(inst, "/getmtdlayout", &mtd_layout_handler, NULL); #ifdef CONFIG_MTK_BOOTMENU_MMC httpd_register_uri_handler(inst, "/gpt.html", &html_handler, NULL); #endif - httpd_register_uri_handler(inst, "/version", &version_handler, NULL); + httpd_register_uri_handler(inst, "/initramfs.html", &html_handler, NULL); + httpd_register_uri_handler(inst, "/main.js", &js_handler, NULL); httpd_register_uri_handler(inst, "/result", &result_handler, NULL); httpd_register_uri_handler(inst, "/style.css", &style_handler, NULL); - httpd_register_uri_handler(inst, "/main.js", &js_handler, NULL); + httpd_register_uri_handler(inst, "/uboot.html", &html_handler, NULL); + httpd_register_uri_handler(inst, "/upload", &upload_handler, NULL); + httpd_register_uri_handler(inst, "/version", &version_handler, NULL); httpd_register_uri_handler(inst, "", ¬_found_handler, NULL); net_loop(MTK_TCP); @@ -419,8 +434,12 @@ static int do_httpd(struct cmd_tbl *cmdtp, int flag, int argc, ret = start_web_failsafe(); - if (upgrade_success) - do_reset(NULL, 0, 0, NULL); + if (upgrade_success) { + if (fw_type == FW_TYPE_INITRD) + boot_from_mem((ulong)upload_data); + else + do_reset(NULL, 0, 0, NULL); + } return ret; } diff --git a/uboot-mtk-20230718-09eda825/failsafe/fsdata/Makefile b/uboot-mtk-20230718-09eda825/failsafe/fsdata/Makefile index b7ccabb40..bfa47dfbb 100644 --- a/uboot-mtk-20230718-09eda825/failsafe/fsdata/Makefile +++ b/uboot-mtk-20230718-09eda825/failsafe/fsdata/Makefile @@ -5,42 +5,50 @@ # FILE_XXXX.o := YYYY.html <- actual html file to be embedded # FSPATH_XXXX.o := ZZZ/WWW.EXT <- virtual fs path to be used inside u-boot -obj-y += index.o -FILE_index.o := index.html -FSPATH_index.o := index.html - -obj-y += main.o -FILE_main.o := main.js -FSPATH_main.o := main.js - -obj-y += flashing.o -FILE_flashing.o := flashing.html -FSPATH_flashing.o := flashing.html - -obj-y += fail.o -FILE_fail.o := fail.html -FSPATH_fail.o := fail.html - obj-y += 404.o FILE_404.o := 404.html FSPATH_404.o := 404.html -obj-y += uboot.o -FILE_uboot.o := uboot.html -FSPATH_uboot.o := uboot.html - obj-y += bl2.o FILE_bl2.o := bl2.html FSPATH_bl2.o := bl2.html +obj-y += booting.o +FILE_booting.o := booting.html +FSPATH_booting.o := booting.html + +obj-y += fail.o +FILE_fail.o := fail.html +FSPATH_fail.o := fail.html + +obj-y += flashing.o +FILE_flashing.o := flashing.html +FSPATH_flashing.o := flashing.html + obj-y += gpt.o FILE_gpt.o := gpt.html FSPATH_gpt.o := gpt.html +obj-y += index.o +FILE_index.o := index.html +FSPATH_index.o := index.html + +obj-y += initramfs.o +FILE_initramfs.o := initramfs.html +FSPATH_initramfs.o := initramfs.html + +obj-y += main.o +FILE_main.o := main.js +FSPATH_main.o := main.js + obj-y += style.o FILE_style.o := style.css FSPATH_style.o := style.css +obj-y += uboot.o +FILE_uboot.o := uboot.html +FSPATH_uboot.o := uboot.html + # customized build rules strip_path = $(subst /,_,$(subst -,_,$(subst .,_,$(1)))) diff --git a/uboot-mtk-20230718-09eda825/failsafe/fsdata/booting.html b/uboot-mtk-20230718-09eda825/failsafe/fsdata/booting.html new file mode 100644 index 000000000..a417a01ce --- /dev/null +++ b/uboot-mtk-20230718-09eda825/failsafe/fsdata/booting.html @@ -0,0 +1,39 @@ + + + + + Booting initramfs + + + + + +
+

BOOTING INITRAMFS

+

+ Your file was successfully uploaded! Booting is in progress, please wait...
+ This page may be in not responding status for a short time. +

+
+
+
+ + diff --git a/uboot-mtk-20230718-09eda825/failsafe/fsdata/initramfs.html b/uboot-mtk-20230718-09eda825/failsafe/fsdata/initramfs.html new file mode 100644 index 000000000..9548fa533 --- /dev/null +++ b/uboot-mtk-20230718-09eda825/failsafe/fsdata/initramfs.html @@ -0,0 +1,39 @@ + + + + + Load initramfs + + + + +
+

LOAD INITRAMFS

+

+ You are going to load initramfs on the device.
+ Please, choose file from your local hard drive and click Upload button. +

+
+ + +
+
+ +
+ + + +
+ WARNINGS +
    +
  • if everything goes well, the device will boot into the initramfs
  • +
  • you can upload whatever you want, so be sure that you choose proper initramfs image for your device
  • +
+
+
+
+ + diff --git a/uboot-mtk-20230718-09eda825/include/failsafe/fw_type.h b/uboot-mtk-20230718-09eda825/include/failsafe/fw_type.h index e802e054e..c4dc9a9e2 100644 --- a/uboot-mtk-20230718-09eda825/include/failsafe/fw_type.h +++ b/uboot-mtk-20230718-09eda825/include/failsafe/fw_type.h @@ -8,6 +8,7 @@ typedef enum { FW_TYPE_BL2, FW_TYPE_FIP, FW_TYPE_FW, + FW_TYPE_INITRD, } failsafe_fw_t; #endif