uboot-mediatek: update to U-Boot 2024.01 release
[openwrt/staging/dangole.git] / package / boot / uboot-mediatek / patches / 230-cmd-add-pstore-check.patch
1 --- a/cmd/pstore.c
2 +++ b/cmd/pstore.c
3 @@ -208,6 +208,58 @@ static int pstore_set(struct cmd_tbl *cm
4 }
5
6 /**
7 + * pstore_check() - Check for pstore records
8 + * @cmdtp: Command data struct pointer
9 + * @flag: Command flag
10 + * @argc: Command-line argument count
11 + * @argv: Array of command-line arguments
12 + *
13 + * Return: 0 if there are records in pstore, 1 otherwise
14 + */
15 +static int pstore_check(struct cmd_tbl *cmdtp, int flag, int argc,
16 + char * const argv[])
17 +{
18 + phys_addr_t ptr;
19 + char *buffer;
20 + u32 size;
21 + int header_len = 0;
22 + bool compressed;
23 +
24 + if (pstore_length == 0) {
25 + printf("Please set PStore configuration\n");
26 + return CMD_RET_USAGE;
27 + }
28 +
29 + if (buffer_size == 0)
30 + pstore_init_buffer_size();
31 +
32 + buffer = malloc_cache_aligned(buffer_size);
33 +
34 + ptr = pstore_addr;
35 + phys_addr_t ptr_end = ptr + pstore_length - pstore_pmsg_size
36 + - pstore_ftrace_size - pstore_console_size;
37 +
38 + while (ptr < ptr_end) {
39 + size = pstore_get_buffer(PERSISTENT_RAM_SIG, ptr,
40 + pstore_record_size, buffer);
41 + ptr += pstore_record_size;
42 +
43 + if (size == 0)
44 + continue;
45 +
46 + header_len = pstore_read_kmsg_hdr(buffer, &compressed);
47 + if (header_len == 0)
48 + continue;
49 +
50 + free(buffer);
51 + return 0;
52 + }
53 +
54 + free(buffer);
55 + return 1;
56 +}
57 +
58 +/**
59 * pstore_print_buffer() - Print buffer
60 * @type: buffer type
61 * @buffer: buffer to print
62 @@ -459,6 +511,7 @@ static int pstore_save(struct cmd_tbl *c
63
64 static struct cmd_tbl cmd_pstore_sub[] = {
65 U_BOOT_CMD_MKENT(set, 8, 0, pstore_set, "", ""),
66 + U_BOOT_CMD_MKENT(check, 1, 0, pstore_check, "", ""),
67 U_BOOT_CMD_MKENT(display, 3, 0, pstore_display, "", ""),
68 U_BOOT_CMD_MKENT(save, 4, 0, pstore_save, "", ""),
69 };
70 @@ -566,6 +619,8 @@ U_BOOT_CMD(pstore, 10, 0, do_pstore,
71 " 'pmsg-size' is the size of the user space logs record.\n"
72 " 'ecc-size' enables/disables ECC support and specifies ECC buffer size in\n"
73 " bytes (0 disables it, 1 is a special value, means 16 bytes ECC).\n"
74 + "pstore check\n"
75 + "- Returns true if there are records in pstore.\n"
76 "pstore display [record-type] [nb]\n"
77 "- Display existing records in pstore reserved memory. A 'record-type' can\n"
78 " be given to only display records of this kind. 'record-type' can be one\n"