From 4c7363068651f222be6150050bb3aa9823ca6f78 Mon Sep 17 00:00:00 2001 From: Massimiliano Minella Date: Thu, 8 Feb 2024 15:58:27 +0100 Subject: cmd: setexpr: fix no matching string in gsub return empty value In gsub, when the destination string is empty, the string 't' is provided and the regular expression doesn't match, then the final result is an empty string. Example: => echo ${foo} => setenv foo => setexpr foo gsub e a bar => echo ${foo} => The variable ${foo} should contain "bar" and the lack of match shouldn't be considered an error. This patch fixes the erroneous behavior by removing the return statement and breaking out of the loop in case of lack of match. Also add a test for the no match case. Signed-off-by: Massimiliano Minella --- cmd/setexpr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'cmd') diff --git a/cmd/setexpr.c b/cmd/setexpr.c index 233471f6cb7..ab76824a32b 100644 --- a/cmd/setexpr.c +++ b/cmd/setexpr.c @@ -216,14 +216,12 @@ int setexpr_regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size, if (res == 0) { if (loop == 0) { debug("%s: No match\n", data); - return 1; } else { - break; + debug("## MATCH ## %s\n", data); } + break; } - debug("## MATCH ## %s\n", data); - if (!s) return 1; @@ -540,7 +538,8 @@ U_BOOT_CMD( " - For each substring matching the regular expression in the\n" " string , substitute the string . The result is\n" " assigned to . If is not supplied, use the old\n" - " value of \n" + " value of . If no substring matching is found in ,\n" + " assign to .\n" "setexpr name sub r s [t]\n" " - Just like gsub(), but replace only the first matching substring" #endif -- cgit v1.3.1 From 9a49f393e4d3f4e83a75bf51e8fd49a3fb615d7b Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 12 Feb 2024 17:53:29 +0100 Subject: cmd: remove common.h from exception command implementations The common.h should not be used anymore. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini --- cmd/arm/exception.c | 1 - cmd/riscv/exception.c | 1 - cmd/sandbox/exception.c | 1 - cmd/x86/exception.c | 1 - 4 files changed, 4 deletions(-) (limited to 'cmd') diff --git a/cmd/arm/exception.c b/cmd/arm/exception.c index 522f6dff53f..98a9795b68c 100644 --- a/cmd/arm/exception.c +++ b/cmd/arm/exception.c @@ -5,7 +5,6 @@ * Copyright (c) 2018, Heinrich Schuchardt */ -#include #include static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc, diff --git a/cmd/riscv/exception.c b/cmd/riscv/exception.c index f38f454a0b1..14ad6c440a5 100644 --- a/cmd/riscv/exception.c +++ b/cmd/riscv/exception.c @@ -5,7 +5,6 @@ * Copyright (c) 2018, Heinrich Schuchardt */ -#include #include static int do_compressed(struct cmd_tbl *cmdtp, int flag, int argc, diff --git a/cmd/sandbox/exception.c b/cmd/sandbox/exception.c index c082401ce6b..cfa153da260 100644 --- a/cmd/sandbox/exception.c +++ b/cmd/sandbox/exception.c @@ -5,7 +5,6 @@ * Copyright (c) 2020, Heinrich Schuchardt */ -#include #include static int do_sigsegv(struct cmd_tbl *cmdtp, int flag, int argc, diff --git a/cmd/x86/exception.c b/cmd/x86/exception.c index 82faaa913e5..14b6bd6f493 100644 --- a/cmd/x86/exception.c +++ b/cmd/x86/exception.c @@ -5,7 +5,6 @@ * Copyright (c) 2018, Heinrich Schuchardt */ -#include #include static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, -- cgit v1.3.1 From 3766a249a3c0686c690bab1ce31a1c1090c74d29 Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Sun, 18 Feb 2024 23:59:35 +0000 Subject: fs: drop reiserfs It was only included by a single board which doesn't appear to have ever used it for any default use cases so drop the filesystem now that isn't used by any in-tree configurations. Signed-off-by: Peter Robinson --- cmd/Kconfig | 9 - cmd/reiser.c | 171 -------- fs/Kconfig | 2 - fs/Makefile | 1 - fs/reiserfs/Kconfig | 0 fs/reiserfs/Makefile | 10 - fs/reiserfs/dev.c | 28 -- fs/reiserfs/mode_string.c | 124 ------ fs/reiserfs/reiserfs.c | 971 ----------------------------------------- fs/reiserfs/reiserfs_private.h | 509 --------------------- include/reiserfs.h | 72 --- 11 files changed, 1897 deletions(-) delete mode 100644 cmd/reiser.c delete mode 100644 fs/reiserfs/Kconfig delete mode 100644 fs/reiserfs/Makefile delete mode 100644 fs/reiserfs/dev.c delete mode 100644 fs/reiserfs/mode_string.c delete mode 100644 fs/reiserfs/reiserfs.c delete mode 100644 fs/reiserfs/reiserfs_private.h delete mode 100644 include/reiserfs.h (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index a86b5705174..438c6d1c480 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2750,15 +2750,6 @@ config MTDPARTS_DEFAULT Defines a default MTD partitioning scheme in the Linux MTD command line partitions format -config CMD_REISER - bool "reiser - Access to reiserfs filesystems" - help - This provides two commands which operate on a resierfs filesystem, - commonly used some years ago: - - reiserls - list files - reiserload - load a file - config CMD_YAFFS2 bool "yaffs2 - Access of YAFFS2 filesystem" depends on YAFFS2 diff --git a/cmd/reiser.c b/cmd/reiser.c deleted file mode 100644 index 707167fcd59..00000000000 --- a/cmd/reiser.c +++ /dev/null @@ -1,171 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2003 - 2004 - * Sysgo Real-Time Solutions, AG - * Pavel Bartusek - */ - -/* - * Reiserfs support - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if !CONFIG_IS_ENABLED(DOS_PARTITION) -#error DOS partition support must be selected -#endif - -/* #define REISER_DEBUG */ - -#ifdef REISER_DEBUG -#define PRINTF(fmt,args...) printf (fmt ,##args) -#else -#define PRINTF(fmt,args...) -#endif - -int do_reiserls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - char *filename = "/"; - int dev, part; - struct blk_desc *dev_desc = NULL; - struct disk_partition info; - - if (argc < 3) - return CMD_RET_USAGE; - - part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); - if (part < 0) - return 1; - - if (argc == 4) { - filename = argv[3]; - } - - dev = dev_desc->devnum; - PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename); - - reiserfs_set_blk_dev(dev_desc, &info); - - if (!reiserfs_mount(info.size)) { - printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); - return 1; - } - - if (reiserfs_ls (filename)) { - printf ("** Error reiserfs_ls() **\n"); - return 1; - }; - - return 0; -} - -U_BOOT_CMD( - reiserls, 4, 1, do_reiserls, - "list files in a directory (default /)", - " [directory]\n" - " - list files from 'dev' on 'interface' in a 'directory'" -); - -/****************************************************************************** - * Reiserfs boot command intepreter. Derived from diskboot - */ -int do_reiserload(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - char *filename = NULL; - int dev, part; - ulong addr = 0, filelen; - struct disk_partition info; - struct blk_desc *dev_desc = NULL; - unsigned long count; - char *addr_str; - - switch (argc) { - case 3: - addr_str = env_get("loadaddr"); - if (addr_str != NULL) { - addr = hextoul(addr_str, NULL); - } else { - addr = CONFIG_SYS_LOAD_ADDR; - } - filename = env_get("bootfile"); - count = 0; - break; - case 4: - addr = hextoul(argv[3], NULL); - filename = env_get("bootfile"); - count = 0; - break; - case 5: - addr = hextoul(argv[3], NULL); - filename = argv[4]; - count = 0; - break; - case 6: - addr = hextoul(argv[3], NULL); - filename = argv[4]; - count = hextoul(argv[5], NULL); - break; - - default: - return CMD_RET_USAGE; - } - - if (!filename) { - puts ("\n** No boot file defined **\n"); - return 1; - } - - part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1); - if (part < 0) - return 1; - - dev = dev_desc->devnum; - - printf("Loading file \"%s\" from %s device %d%c%c\n", - filename, argv[1], dev, - part ? ':' : ' ', part ? part + '0' : ' '); - - reiserfs_set_blk_dev(dev_desc, &info); - - if (!reiserfs_mount(info.size)) { - printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part); - return 1; - } - - filelen = reiserfs_open(filename); - if (filelen < 0) { - printf("** File not found %s **\n", filename); - return 1; - } - if ((count < filelen) && (count != 0)) { - filelen = count; - } - - if (reiserfs_read((char *)addr, filelen) != filelen) { - printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part); - return 1; - } - - /* Loading ok, update default load address */ - image_load_addr = addr; - - printf ("\n%ld bytes read\n", filelen); - env_set_hex("filesize", filelen); - - return filelen; -} - -U_BOOT_CMD( - reiserload, 6, 0, do_reiserload, - "load binary file from a Reiser filesystem", - " [addr] [filename] [bytes]\n" - " - load binary file 'filename' from 'dev' on 'interface'\n" - " to address 'addr' from dos filesystem" -); diff --git a/fs/Kconfig b/fs/Kconfig index aa13d4faa77..744c9812b12 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -10,8 +10,6 @@ source "fs/cbfs/Kconfig" source "fs/ext4/Kconfig" -source "fs/reiserfs/Kconfig" - source "fs/fat/Kconfig" source "fs/jffs2/Kconfig" diff --git a/fs/Makefile b/fs/Makefile index 4bed2ff2d99..7b05c79e0cc 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -19,7 +19,6 @@ obj-$(CONFIG_CMD_CRAMFS) += cramfs/ obj-$(CONFIG_FS_EXT4) += ext4/ obj-$(CONFIG_FS_FAT) += fat/ obj-$(CONFIG_FS_JFFS2) += jffs2/ -obj-$(CONFIG_CMD_REISER) += reiserfs/ obj-$(CONFIG_SANDBOX) += sandbox/ obj-$(CONFIG_SEMIHOSTING) += semihostingfs.o obj-$(CONFIG_CMD_UBIFS) += ubifs/ diff --git a/fs/reiserfs/Kconfig b/fs/reiserfs/Kconfig deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/fs/reiserfs/Makefile b/fs/reiserfs/Makefile deleted file mode 100644 index 63dd8957534..00000000000 --- a/fs/reiserfs/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0+ -# -# (C) Copyright 2006 -# Wolfgang Denk, DENX Software Engineering, wd@denx.de. -# -# (C) Copyright 2003 -# Pavel Bartusek, Sysgo Real-Time Solutions AG, pba@sysgo.de -# - -obj-y := reiserfs.o dev.o mode_string.o diff --git a/fs/reiserfs/dev.c b/fs/reiserfs/dev.c deleted file mode 100644 index 5d9c26489aa..00000000000 --- a/fs/reiserfs/dev.c +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2003 - 2004 - * Sysgo AG, , Pavel Bartusek - */ - - -#include -#include -#include -#include -#include "reiserfs_private.h" - -static struct blk_desc *reiserfs_blk_desc; -static struct disk_partition *part_info; - - -void reiserfs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info) -{ - reiserfs_blk_desc = rbdd; - part_info = info; -} - -int reiserfs_devread(int sector, int byte_offset, int byte_len, char *buf) -{ - return fs_devread(reiserfs_blk_desc, part_info, sector, byte_offset, - byte_len, buf); -} diff --git a/fs/reiserfs/mode_string.c b/fs/reiserfs/mode_string.c deleted file mode 100644 index 638cf6368da..00000000000 --- a/fs/reiserfs/mode_string.c +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * mode_string implementation for busybox - * - * Copyright (C) 2003 Manuel Novoa III - */ - -/* Aug 13, 2003 - * Fix a bug reported by junkio@cox.net involving the mode_chars index. - */ - - -#include -#include - -#if ( S_ISUID != 04000 ) || ( S_ISGID != 02000 ) || ( S_ISVTX != 01000 ) \ - || ( S_IRUSR != 00400 ) || ( S_IWUSR != 00200 ) || ( S_IXUSR != 00100 ) \ - || ( S_IRGRP != 00040 ) || ( S_IWGRP != 00020 ) || ( S_IXGRP != 00010 ) \ - || ( S_IROTH != 00004 ) || ( S_IWOTH != 00002 ) || ( S_IXOTH != 00001 ) -#error permission bitflag value assumption(s) violated! -#endif - -#if ( S_IFSOCK!= 0140000 ) || ( S_IFLNK != 0120000 ) \ - || ( S_IFREG != 0100000 ) || ( S_IFBLK != 0060000 ) \ - || ( S_IFDIR != 0040000 ) || ( S_IFCHR != 0020000 ) \ - || ( S_IFIFO != 0010000 ) -#warning mode type bitflag value assumption(s) violated! falling back to larger version - -#if (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX) == 07777 -#undef mode_t -#define mode_t unsigned short -#endif - -static const mode_t mode_flags[] = { - S_IRUSR, S_IWUSR, S_IXUSR, S_ISUID, - S_IRGRP, S_IWGRP, S_IXGRP, S_ISGID, - S_IROTH, S_IWOTH, S_IXOTH, S_ISVTX -}; - -/* The static const char arrays below are duplicated for the two cases - * because moving them ahead of the mode_flags declaration cause a text - * size increase with the gcc version I'm using. */ - -/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', - * and 'B' types don't appear to be available on linux. So I removed them. */ -static const char type_chars[16] = "?pc?d?b?-?l?s???"; -/* 0123456789abcdef */ -static const char mode_chars[7] = "rwxSTst"; - -const char *bb_mode_string(int mode) -{ - static char buf[12]; - char *p = buf; - - int i, j, k; - - *p = type_chars[ (mode >> 12) & 0xf ]; - i = 0; - do { - j = k = 0; - do { - *++p = '-'; - if (mode & mode_flags[i+j]) { - *p = mode_chars[j]; - k = j; - } - } while (++j < 3); - if (mode & mode_flags[i+j]) { - *p = mode_chars[3 + (k & 2) + ((i&8) >> 3)]; - } - i += 4; - } while (i < 12); - - /* Note: We don't bother with nul termination because bss initialization - * should have taken care of that for us. If the user scribbled in buf - * memory, they deserve whatever happens. But we'll at least assert. */ - if (buf[10] != 0) return NULL; - - return buf; -} - -#else - -/* The previous version used "0pcCd?bB-?l?s???". However, the '0', 'C', - * and 'B' types don't appear to be available on linux. So I removed them. */ -static const char type_chars[16] = "?pc?d?b?-?l?s???"; -/* 0123456789abcdef */ -static const char mode_chars[7] = "rwxSTst"; - -const char *bb_mode_string(int mode) -{ - static char buf[12]; - char *p = buf; - - int i, j, k, m; - - *p = type_chars[ (mode >> 12) & 0xf ]; - i = 0; - m = 0400; - do { - j = k = 0; - do { - *++p = '-'; - if (mode & m) { - *p = mode_chars[j]; - k = j; - } - m >>= 1; - } while (++j < 3); - ++i; - if (mode & (010000 >> i)) { - *p = mode_chars[3 + (k & 2) + (i == 3)]; - } - } while (i < 3); - - /* Note: We don't bother with nul termination because bss initialization - * should have taken care of that for us. If the user scribbled in buf - * memory, they deserve whatever happens. But we'll at least assert. */ - if (buf[10] != 0) return NULL; - - return buf; -} - -#endif diff --git a/fs/reiserfs/reiserfs.c b/fs/reiserfs/reiserfs.c deleted file mode 100644 index 635aab2eba7..00000000000 --- a/fs/reiserfs/reiserfs.c +++ /dev/null @@ -1,971 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README - * - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000, 2001 Free Software Foundation, Inc. - * - * (C) Copyright 2003 - 2004 - * Sysgo AG, , Pavel Bartusek - * - */ - -/* An implementation for the ReiserFS filesystem ported from GRUB. - * Some parts of this code (mainly the structures and defines) are - * from the original reiser fs code, as found in the linux kernel. - */ - -#include -#include -#include -#include -#include -#include - -#include "reiserfs_private.h" - -#undef REISERDEBUG - -/* Some parts of this code (mainly the structures and defines) are - * from the original reiser fs code, as found in the linux kernel. - */ - -static char fsys_buf[FSYS_BUFLEN]; -static reiserfs_error_t errnum = ERR_NONE; -static int print_possibilities; -static unsigned int filepos, filemax; - -static int -substring (const char *s1, const char *s2) -{ - while (*s1 == *s2) - { - /* The strings match exactly. */ - if (! *(s1++)) - return 0; - s2 ++; - } - - /* S1 is a substring of S2. */ - if (*s1 == 0) - return -1; - - /* S1 isn't a substring. */ - return 1; -} - -static void sd_print_item (struct item_head * ih, char * item) -{ - char filetime[30]; - time_t ttime; - - if (stat_data_v1 (ih)) { - struct stat_data_v1 * sd = (struct stat_data_v1 *)item; - ttime = sd_v1_mtime(sd); - ctime_r(&ttime, filetime); - printf ("%-10s %4hd %6d %6d %9d %24.24s", - bb_mode_string(sd_v1_mode(sd)), sd_v1_nlink(sd),sd_v1_uid(sd), sd_v1_gid(sd), - sd_v1_size(sd), filetime); - } else { - struct stat_data * sd = (struct stat_data *)item; - ttime = sd_v2_mtime(sd); - ctime_r(&ttime, filetime); - printf ("%-10s %4d %6d %6d %9d %24.24s", - bb_mode_string(sd_v2_mode(sd)), sd_v2_nlink(sd),sd_v2_uid(sd),sd_v2_gid(sd), - (__u32) sd_v2_size(sd), filetime); - } -} - -static int -journal_read (int block, int len, char *buffer) -{ - return reiserfs_devread ((INFO->journal_block + block) << INFO->blocksize_shift, - 0, len, buffer); -} - -/* Read a block from ReiserFS file system, taking the journal into - * account. If the block nr is in the journal, the block from the - * journal taken. - */ -static int -block_read (unsigned int blockNr, int start, int len, char *buffer) -{ - int transactions = INFO->journal_transactions; - int desc_block = INFO->journal_first_desc; - int journal_mask = INFO->journal_block_count - 1; - int translatedNr = blockNr; - __u32 *journal_table = JOURNAL_START; - while (transactions-- > 0) - { - int i = 0; - int j_len; - if (__le32_to_cpu(*journal_table) != 0xffffffff) - { - /* Search for the blockNr in cached journal */ - j_len = __le32_to_cpu(*journal_table++); - while (i++ < j_len) - { - if (__le32_to_cpu(*journal_table++) == blockNr) - { - journal_table += j_len - i; - goto found; - } - } - } - else - { - /* This is the end of cached journal marker. The remaining - * transactions are still on disk. - */ - struct reiserfs_journal_desc desc; - struct reiserfs_journal_commit commit; - - if (! journal_read (desc_block, sizeof (desc), (char *) &desc)) - return 0; - - j_len = __le32_to_cpu(desc.j_len); - while (i < j_len && i < JOURNAL_TRANS_HALF) - if (__le32_to_cpu(desc.j_realblock[i++]) == blockNr) - goto found; - - if (j_len >= JOURNAL_TRANS_HALF) - { - int commit_block = (desc_block + 1 + j_len) & journal_mask; - if (! journal_read (commit_block, - sizeof (commit), (char *) &commit)) - return 0; - while (i < j_len) - if (__le32_to_cpu(commit.j_realblock[i++ - JOURNAL_TRANS_HALF]) == blockNr) - goto found; - } - } - goto not_found; - - found: - translatedNr = INFO->journal_block + ((desc_block + i) & journal_mask); -#ifdef REISERDEBUG - printf ("block_read: block %d is mapped to journal block %d.\n", - blockNr, translatedNr - INFO->journal_block); -#endif - /* We must continue the search, as this block may be overwritten - * in later transactions. - */ - not_found: - desc_block = (desc_block + 2 + j_len) & journal_mask; - } - return reiserfs_devread (translatedNr << INFO->blocksize_shift, start, len, buffer); -} - -/* Init the journal data structure. We try to cache as much as - * possible in the JOURNAL_START-JOURNAL_END space, but if it is full - * we can still read the rest from the disk on demand. - * - * The first number of valid transactions and the descriptor block of the - * first valid transaction are held in INFO. The transactions are all - * adjacent, but we must take care of the journal wrap around. - */ -static int -journal_init (void) -{ - unsigned int block_count = INFO->journal_block_count; - unsigned int desc_block; - unsigned int commit_block; - unsigned int next_trans_id; - struct reiserfs_journal_header header; - struct reiserfs_journal_desc desc; - struct reiserfs_journal_commit commit; - __u32 *journal_table = JOURNAL_START; - - journal_read (block_count, sizeof (header), (char *) &header); - desc_block = __le32_to_cpu(header.j_first_unflushed_offset); - if (desc_block >= block_count) - return 0; - - INFO->journal_first_desc = desc_block; - next_trans_id = __le32_to_cpu(header.j_last_flush_trans_id) + 1; - -#ifdef REISERDEBUG - printf ("journal_init: last flushed %d\n", - __le32_to_cpu(header.j_last_flush_trans_id)); -#endif - - while (1) - { - journal_read (desc_block, sizeof (desc), (char *) &desc); - if (substring (JOURNAL_DESC_MAGIC, desc.j_magic) > 0 - || __le32_to_cpu(desc.j_trans_id) != next_trans_id - || __le32_to_cpu(desc.j_mount_id) != __le32_to_cpu(header.j_mount_id)) - /* no more valid transactions */ - break; - - commit_block = (desc_block + __le32_to_cpu(desc.j_len) + 1) & (block_count - 1); - journal_read (commit_block, sizeof (commit), (char *) &commit); - if (__le32_to_cpu(desc.j_trans_id) != commit.j_trans_id - || __le32_to_cpu(desc.j_len) != __le32_to_cpu(commit.j_len)) - /* no more valid transactions */ - break; - -#ifdef REISERDEBUG - printf ("Found valid transaction %d/%d at %d.\n", - __le32_to_cpu(desc.j_trans_id), __le32_to_cpu(desc.j_mount_id), desc_block); -#endif - - next_trans_id++; - if (journal_table < JOURNAL_END) - { - if ((journal_table + 1 + __le32_to_cpu(desc.j_len)) >= JOURNAL_END) - { - /* The table is almost full; mark the end of the cached - * journal.*/ - *journal_table = __cpu_to_le32(0xffffffff); - journal_table = JOURNAL_END; - } - else - { - unsigned int i; - /* Cache the length and the realblock numbers in the table. - * The block number of descriptor can easily be computed. - * and need not to be stored here. - */ - - /* both are in the little endian format */ - *journal_table++ = desc.j_len; - for (i = 0; i < __le32_to_cpu(desc.j_len) && i < JOURNAL_TRANS_HALF; i++) - { - /* both are in the little endian format */ - *journal_table++ = desc.j_realblock[i]; -#ifdef REISERDEBUG - printf ("block %d is in journal %d.\n", - __le32_to_cpu(desc.j_realblock[i]), desc_block); -#endif - } - for ( ; i < __le32_to_cpu(desc.j_len); i++) - { - /* both are in the little endian format */ - *journal_table++ = commit.j_realblock[i-JOURNAL_TRANS_HALF]; -#ifdef REISERDEBUG - printf ("block %d is in journal %d.\n", - __le32_to_cpu(commit.j_realblock[i-JOURNAL_TRANS_HALF]), - desc_block); -#endif - } - } - } - desc_block = (commit_block + 1) & (block_count - 1); - } -#ifdef REISERDEBUG - printf ("Transaction %d/%d at %d isn't valid.\n", - __le32_to_cpu(desc.j_trans_id), __le32_to_cpu(desc.j_mount_id), desc_block); -#endif - - INFO->journal_transactions - = next_trans_id - __le32_to_cpu(header.j_last_flush_trans_id) - 1; - return errnum == 0; -} - -/* check filesystem types and read superblock into memory buffer */ -int -reiserfs_mount (unsigned part_length) -{ - struct reiserfs_super_block super; - int superblock = REISERFS_DISK_OFFSET_IN_BYTES >> SECTOR_BITS; - char *cache; - - if (part_length < superblock + (sizeof (super) >> SECTOR_BITS) - || ! reiserfs_devread (superblock, 0, sizeof (struct reiserfs_super_block), - (char *) &super) - || (substring (REISER3FS_SUPER_MAGIC_STRING, super.s_magic) > 0 - && substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0 - && substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) > 0) - || (/* check that this is not a copy inside the journal log */ - sb_journal_block(&super) * sb_blocksize(&super) - <= REISERFS_DISK_OFFSET_IN_BYTES)) - { - /* Try old super block position */ - superblock = REISERFS_OLD_DISK_OFFSET_IN_BYTES >> SECTOR_BITS; - if (part_length < superblock + (sizeof (super) >> SECTOR_BITS) - || ! reiserfs_devread (superblock, 0, sizeof (struct reiserfs_super_block), - (char *) &super)) - return 0; - - if (substring (REISER2FS_SUPER_MAGIC_STRING, super.s_magic) > 0 - && substring (REISERFS_SUPER_MAGIC_STRING, super.s_magic) > 0) - { - /* pre journaling super block ? */ - if (substring (REISERFS_SUPER_MAGIC_STRING, - (char*) ((int) &super + 20)) > 0) - return 0; - - set_sb_blocksize(&super, REISERFS_OLD_BLOCKSIZE); - set_sb_journal_block(&super, 0); - set_sb_version(&super, 0); - } - } - - /* check the version number. */ - if (sb_version(&super) > REISERFS_MAX_SUPPORTED_VERSION) - return 0; - - INFO->version = sb_version(&super); - INFO->blocksize = sb_blocksize(&super); - INFO->fullblocksize_shift = log2 (sb_blocksize(&super)); - INFO->blocksize_shift = INFO->fullblocksize_shift - SECTOR_BITS; - INFO->cached_slots = - (FSYSREISER_CACHE_SIZE >> INFO->fullblocksize_shift) - 1; - -#ifdef REISERDEBUG - printf ("reiserfs_mount: version=%d, blocksize=%d\n", - INFO->version, INFO->blocksize); -#endif /* REISERDEBUG */ - - /* Clear node cache. */ - memset (INFO->blocks, 0, sizeof (INFO->blocks)); - - if (sb_blocksize(&super) < FSYSREISER_MIN_BLOCKSIZE - || sb_blocksize(&super) > FSYSREISER_MAX_BLOCKSIZE - || (SECTOR_SIZE << INFO->blocksize_shift) != sb_blocksize(&super)) - return 0; - - /* Initialize journal code. If something fails we end with zero - * journal_transactions, so we don't access the journal at all. - */ - INFO->journal_transactions = 0; - if (sb_journal_block(&super) != 0 && super.s_journal_dev == 0) - { - INFO->journal_block = sb_journal_block(&super); - INFO->journal_block_count = sb_journal_size(&super); - if (is_power_of_two (INFO->journal_block_count)) - journal_init (); - - /* Read in super block again, maybe it is in the journal */ - block_read (superblock >> INFO->blocksize_shift, - 0, sizeof (struct reiserfs_super_block), (char *) &super); - } - - if (! block_read (sb_root_block(&super), 0, INFO->blocksize, (char*) ROOT)) - return 0; - - cache = ROOT; - INFO->tree_depth = __le16_to_cpu(BLOCKHEAD (cache)->blk_level); - -#ifdef REISERDEBUG - printf ("root read_in: block=%d, depth=%d\n", - sb_root_block(&super), INFO->tree_depth); -#endif /* REISERDEBUG */ - - if (INFO->tree_depth >= MAX_HEIGHT) - return 0; - if (INFO->tree_depth == DISK_LEAF_NODE_LEVEL) - { - /* There is only one node in the whole filesystem, - * which is simultanously leaf and root */ - memcpy (LEAF, ROOT, INFO->blocksize); - } - return 1; -} - -/***************** TREE ACCESSING METHODS *****************************/ - -/* I assume you are familiar with the ReiserFS tree, if not go to - * http://www.namesys.com/content_table.html - * - * My tree node cache is organized as following - * 0 ROOT node - * 1 LEAF node (if the ROOT is also a LEAF it is copied here - * 2-n other nodes on current path from bottom to top. - * if there is not enough space in the cache, the top most are - * omitted. - * - * I have only two methods to find a key in the tree: - * search_stat(dir_id, objectid) searches for the stat entry (always - * the first entry) of an object. - * next_key() gets the next key in tree order. - * - * This means, that I can only sequential reads of files are - * efficient, but this really doesn't hurt for grub. - */ - -/* Read in the node at the current path and depth into the node cache. - * You must set INFO->blocks[depth] before. - */ -static char * -read_tree_node (unsigned int blockNr, int depth) -{ - char* cache = CACHE(depth); - int num_cached = INFO->cached_slots; - if (depth < num_cached) - { - /* This is the cached part of the path. Check if same block is - * needed. - */ - if (blockNr == INFO->blocks[depth]) - return cache; - } - else - cache = CACHE(num_cached); - -#ifdef REISERDEBUG - printf (" next read_in: block=%d (depth=%d)\n", - blockNr, depth); -#endif /* REISERDEBUG */ - if (! block_read (blockNr, 0, INFO->blocksize, cache)) - return 0; - /* Make sure it has the right node level */ - if (__le16_to_cpu(BLOCKHEAD (cache)->blk_level) != depth) - { - errnum = ERR_FSYS_CORRUPT; - return 0; - } - - INFO->blocks[depth] = blockNr; - return cache; -} - -/* Get the next key, i.e. the key following the last retrieved key in - * tree order. INFO->current_ih and - * INFO->current_info are adapted accordingly. */ -static int -next_key (void) -{ - int depth; - struct item_head *ih = INFO->current_ih + 1; - char *cache; - -#ifdef REISERDEBUG - printf ("next_key:\n old ih: key %d:%d:%d:%d version:%d\n", - __le32_to_cpu(INFO->current_ih->ih_key.k_dir_id), - __le32_to_cpu(INFO->current_ih->ih_key.k_objectid), - __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_offset), - __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_uniqueness), - __le16_to_cpu(INFO->current_ih->ih_version)); -#endif /* REISERDEBUG */ - - if (ih == &ITEMHEAD[__le16_to_cpu(BLOCKHEAD (LEAF)->blk_nr_item)]) - { - depth = DISK_LEAF_NODE_LEVEL; - /* The last item, was the last in the leaf node. - * Read in the next block - */ - do - { - if (depth == INFO->tree_depth) - { - /* There are no more keys at all. - * Return a dummy item with MAX_KEY */ - ih = (struct item_head *) &BLOCKHEAD (LEAF)->blk_right_delim_key; - goto found; - } - depth++; -#ifdef REISERDEBUG - printf (" depth=%d, i=%d\n", depth, INFO->next_key_nr[depth]); -#endif /* REISERDEBUG */ - } - while (INFO->next_key_nr[depth] == 0); - - if (depth == INFO->tree_depth) - cache = ROOT; - else if (depth <= INFO->cached_slots) - cache = CACHE (depth); - else - { - cache = read_tree_node (INFO->blocks[depth], depth); - if (! cache) - return 0; - } - - do - { - int nr_item = __le16_to_cpu(BLOCKHEAD (cache)->blk_nr_item); - int key_nr = INFO->next_key_nr[depth]++; -#ifdef REISERDEBUG - printf (" depth=%d, i=%d/%d\n", depth, key_nr, nr_item); -#endif /* REISERDEBUG */ - if (key_nr == nr_item) - /* This is the last item in this block, set the next_key_nr to 0 */ - INFO->next_key_nr[depth] = 0; - - cache = read_tree_node (dc_block_number(&(DC (cache)[key_nr])), --depth); - if (! cache) - return 0; - } - while (depth > DISK_LEAF_NODE_LEVEL); - - ih = ITEMHEAD; - } - found: - INFO->current_ih = ih; - INFO->current_item = &LEAF[__le16_to_cpu(ih->ih_item_location)]; -#ifdef REISERDEBUG - printf (" new ih: key %d:%d:%d:%d version:%d\n", - __le32_to_cpu(INFO->current_ih->ih_key.k_dir_id), - __le32_to_cpu(INFO->current_ih->ih_key.k_objectid), - __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_offset), - __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_uniqueness), - __le16_to_cpu(INFO->current_ih->ih_version)); -#endif /* REISERDEBUG */ - return 1; -} - -/* preconditions: reiserfs_mount already executed, therefore - * INFO block is valid - * returns: 0 if error (errnum is set), - * nonzero iff we were able to find the key successfully. - * postconditions: on a nonzero return, the current_ih and - * current_item fields describe the key that equals the - * searched key. INFO->next_key contains the next key after - * the searched key. - * side effects: messes around with the cache. - */ -static int -search_stat (__u32 dir_id, __u32 objectid) -{ - char *cache; - int depth; - int nr_item; - int i; - struct item_head *ih; -#ifdef REISERDEBUG - printf ("search_stat:\n key %d:%d:0:0\n", dir_id, objectid); -#endif /* REISERDEBUG */ - - depth = INFO->tree_depth; - cache = ROOT; - - while (depth > DISK_LEAF_NODE_LEVEL) - { - struct key *key; - nr_item = __le16_to_cpu(BLOCKHEAD (cache)->blk_nr_item); - - key = KEY (cache); - - for (i = 0; i < nr_item; i++) - { - if (__le32_to_cpu(key->k_dir_id) > dir_id - || (__le32_to_cpu(key->k_dir_id) == dir_id - && (__le32_to_cpu(key->k_objectid) > objectid - || (__le32_to_cpu(key->k_objectid) == objectid - && (__le32_to_cpu(key->u.v1.k_offset) - | __le32_to_cpu(key->u.v1.k_uniqueness)) > 0)))) - break; - key++; - } - -#ifdef REISERDEBUG - printf (" depth=%d, i=%d/%d\n", depth, i, nr_item); -#endif /* REISERDEBUG */ - INFO->next_key_nr[depth] = (i == nr_item) ? 0 : i+1; - cache = read_tree_node (dc_block_number(&(DC (cache)[i])), --depth); - if (! cache) - return 0; - } - - /* cache == LEAF */ - nr_item = __le16_to_cpu(BLOCKHEAD (LEAF)->blk_nr_item); - ih = ITEMHEAD; - for (i = 0; i < nr_item; i++) - { - if (__le32_to_cpu(ih->ih_key.k_dir_id) == dir_id - && __le32_to_cpu(ih->ih_key.k_objectid) == objectid - && __le32_to_cpu(ih->ih_key.u.v1.k_offset) == 0 - && __le32_to_cpu(ih->ih_key.u.v1.k_uniqueness) == 0) - { -#ifdef REISERDEBUG - printf (" depth=%d, i=%d/%d\n", depth, i, nr_item); -#endif /* REISERDEBUG */ - INFO->current_ih = ih; - INFO->current_item = &LEAF[__le16_to_cpu(ih->ih_item_location)]; - return 1; - } - ih++; - } - errnum = ERR_FSYS_CORRUPT; - return 0; -} - -int -reiserfs_read (char *buf, unsigned len) -{ - unsigned int blocksize; - unsigned int offset; - unsigned int to_read; - char *prev_buf = buf; - -#ifdef REISERDEBUG - printf ("reiserfs_read: filepos=%d len=%d, offset=%Lx\n", - filepos, len, (__u64) IH_KEY_OFFSET (INFO->current_ih) - 1); -#endif /* REISERDEBUG */ - - if (__le32_to_cpu(INFO->current_ih->ih_key.k_objectid) != INFO->fileinfo.k_objectid - || IH_KEY_OFFSET (INFO->current_ih) > filepos + 1) - { - search_stat (INFO->fileinfo.k_dir_id, INFO->fileinfo.k_objectid); - goto get_next_key; - } - - while (! errnum) - { - if (__le32_to_cpu(INFO->current_ih->ih_key.k_objectid) != INFO->fileinfo.k_objectid) { - break; - } - - offset = filepos - IH_KEY_OFFSET (INFO->current_ih) + 1; - blocksize = __le16_to_cpu(INFO->current_ih->ih_item_len); - -#ifdef REISERDEBUG - printf (" loop: filepos=%d len=%d, offset=%d blocksize=%d\n", - filepos, len, offset, blocksize); -#endif /* REISERDEBUG */ - - if (IH_KEY_ISTYPE(INFO->current_ih, TYPE_DIRECT) - && offset < blocksize) - { -#ifdef REISERDEBUG - printf ("direct_read: offset=%d, blocksize=%d\n", - offset, blocksize); -#endif /* REISERDEBUG */ - to_read = blocksize - offset; - if (to_read > len) - to_read = len; - - memcpy (buf, INFO->current_item + offset, to_read); - goto update_buf_len; - } - else if (IH_KEY_ISTYPE(INFO->current_ih, TYPE_INDIRECT)) - { - blocksize = (blocksize >> 2) << INFO->fullblocksize_shift; -#ifdef REISERDEBUG - printf ("indirect_read: offset=%d, blocksize=%d\n", - offset, blocksize); -#endif /* REISERDEBUG */ - - while (offset < blocksize) - { - __u32 blocknr = __le32_to_cpu(((__u32 *) INFO->current_item) - [offset >> INFO->fullblocksize_shift]); - int blk_offset = offset & (INFO->blocksize-1); - to_read = INFO->blocksize - blk_offset; - if (to_read > len) - to_read = len; - - /* Journal is only for meta data. Data blocks can be read - * directly without using block_read - */ - reiserfs_devread (blocknr << INFO->blocksize_shift, - blk_offset, to_read, buf); - update_buf_len: - len -= to_read; - buf += to_read; - offset += to_read; - filepos += to_read; - if (len == 0) - goto done; - } - } - get_next_key: - next_key (); - } - done: - return errnum ? 0 : buf - prev_buf; -} - - -/* preconditions: reiserfs_mount already executed, therefore - * INFO block is valid - * returns: 0 if error, nonzero iff we were able to find the file successfully - * postconditions: on a nonzero return, INFO->fileinfo contains the info - * of the file we were trying to look up, filepos is 0 and filemax is - * the size of the file. - */ -static int -reiserfs_dir (char *dirname) -{ - struct reiserfs_de_head *de_head; - char *rest, ch; - __u32 dir_id, objectid, parent_dir_id = 0, parent_objectid = 0; -#ifndef STAGE1_5 - int do_possibilities = 0; -#endif /* ! STAGE1_5 */ - char linkbuf[PATH_MAX]; /* buffer for following symbolic links */ - int link_count = 0; - int mode; - - dir_id = REISERFS_ROOT_PARENT_OBJECTID; - objectid = REISERFS_ROOT_OBJECTID; - - while (1) - { -#ifdef REISERDEBUG - printf ("dirname=%s\n", dirname); -#endif /* REISERDEBUG */ - - /* Search for the stat info first. */ - if (! search_stat (dir_id, objectid)) - return 0; - -#ifdef REISERDEBUG - printf ("sd_mode=%x sd_size=%d\n", - stat_data_v1(INFO->current_ih) ? sd_v1_mode((struct stat_data_v1 *) INFO->current_item) : - sd_v2_mode((struct stat_data *) (INFO->current_item)), - stat_data_v1(INFO->current_ih) ? sd_v1_size((struct stat_data_v1 *) INFO->current_item) : - sd_v2_size((struct stat_data *) INFO->current_item) - ); - -#endif /* REISERDEBUG */ - mode = stat_data_v1(INFO->current_ih) ? - sd_v1_mode((struct stat_data_v1 *) INFO->current_item) : - sd_v2_mode((struct stat_data *) INFO->current_item); - - /* If we've got a symbolic link, then chase it. */ - if (S_ISLNK (mode)) - { - unsigned int len; - if (++link_count > MAX_LINK_COUNT) - { - errnum = ERR_SYMLINK_LOOP; - return 0; - } - - /* Get the symlink size. */ - filemax = stat_data_v1(INFO->current_ih) ? - sd_v1_size((struct stat_data_v1 *) INFO->current_item) : - sd_v2_size((struct stat_data *) INFO->current_item); - - /* Find out how long our remaining name is. */ - len = 0; - while (dirname[len] && !isspace (dirname[len])) - len++; - - if (filemax + len > sizeof (linkbuf) - 1) - { - errnum = ERR_FILELENGTH; - return 0; - } - - /* Copy the remaining name to the end of the symlink data. - Note that DIRNAME and LINKBUF may overlap! */ - memmove (linkbuf + filemax, dirname, len+1); - - INFO->fileinfo.k_dir_id = dir_id; - INFO->fileinfo.k_objectid = objectid; - filepos = 0; - if (! next_key () - || reiserfs_read (linkbuf, filemax) != filemax) - { - if (! errnum) - errnum = ERR_FSYS_CORRUPT; - return 0; - } - -#ifdef REISERDEBUG - printf ("symlink=%s\n", linkbuf); -#endif /* REISERDEBUG */ - - dirname = linkbuf; - if (*dirname == '/') - { - /* It's an absolute link, so look it up in root. */ - dir_id = REISERFS_ROOT_PARENT_OBJECTID; - objectid = REISERFS_ROOT_OBJECTID; - } - else - { - /* Relative, so look it up in our parent directory. */ - dir_id = parent_dir_id; - objectid = parent_objectid; - } - - /* Now lookup the new name. */ - continue; - } - - /* if we have a real file (and we're not just printing possibilities), - then this is where we want to exit */ - - if (! *dirname || isspace (*dirname)) - { - if (! S_ISREG (mode)) - { - errnum = ERR_BAD_FILETYPE; - return 0; - } - - filepos = 0; - filemax = stat_data_v1(INFO->current_ih) ? - sd_v1_size((struct stat_data_v1 *) INFO->current_item) : - sd_v2_size((struct stat_data *) INFO->current_item); -#if 0 - /* If this is a new stat data and size is > 4GB set filemax to - * maximum - */ - if (__le16_to_cpu(INFO->current_ih->ih_version) == ITEM_VERSION_2 - && sd_size_hi((struct stat_data *) INFO->current_item) > 0) - filemax = 0xffffffff; -#endif - INFO->fileinfo.k_dir_id = dir_id; - INFO->fileinfo.k_objectid = objectid; - return next_key (); - } - - /* continue with the file/directory name interpretation */ - while (*dirname == '/') - dirname++; - if (! S_ISDIR (mode)) - { - errnum = ERR_BAD_FILETYPE; - return 0; - } - for (rest = dirname; (ch = *rest) && ! isspace (ch) && ch != '/'; rest++); - *rest = 0; - -# ifndef STAGE1_5 - if (print_possibilities && ch != '/') - do_possibilities = 1; -# endif /* ! STAGE1_5 */ - - while (1) - { - char *name_end; - int num_entries; - - if (! next_key ()) - return 0; -#ifdef REISERDEBUG - printf ("ih: key %d:%d:%d:%d version:%d\n", - __le32_to_cpu(INFO->current_ih->ih_key.k_dir_id), - __le32_to_cpu(INFO->current_ih->ih_key.k_objectid), - __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_offset), - __le32_to_cpu(INFO->current_ih->ih_key.u.v1.k_uniqueness), - __le16_to_cpu(INFO->current_ih->ih_version)); -#endif /* REISERDEBUG */ - - if (__le32_to_cpu(INFO->current_ih->ih_key.k_objectid) != objectid) - break; - - name_end = INFO->current_item + __le16_to_cpu(INFO->current_ih->ih_item_len); - de_head = (struct reiserfs_de_head *) INFO->current_item; - num_entries = __le16_to_cpu(INFO->current_ih->u.ih_entry_count); - while (num_entries > 0) - { - char *filename = INFO->current_item + deh_location(de_head); - char tmp = *name_end; - if ((deh_state(de_head) & DEH_Visible)) - { - int cmp; - /* Directory names in ReiserFS are not null - * terminated. We write a temporary 0 behind it. - * NOTE: that this may overwrite the first block in - * the tree cache. That doesn't hurt as long as we - * don't call next_key () in between. - */ - *name_end = 0; - cmp = substring (dirname, filename); - *name_end = tmp; -# ifndef STAGE1_5 - if (do_possibilities) - { - if (cmp <= 0) - { - char fn[PATH_MAX]; - struct fsys_reiser_info info_save; - - if (print_possibilities > 0) - print_possibilities = -print_possibilities; - *name_end = 0; - strcpy(fn, filename); - *name_end = tmp; - - /* If NAME is "." or "..", do not count it. */ - if (strcmp (fn, ".") != 0 && strcmp (fn, "..") != 0) { - memcpy(&info_save, INFO, sizeof(struct fsys_reiser_info)); - search_stat (deh_dir_id(de_head), deh_objectid(de_head)); - sd_print_item(INFO->current_ih, INFO->current_item); - printf(" %s\n", fn); - search_stat (dir_id, objectid); - memcpy(INFO, &info_save, sizeof(struct fsys_reiser_info)); - } - } - } - else -# endif /* ! STAGE1_5 */ - if (cmp == 0) - goto found; - } - /* The beginning of this name marks the end of the next name. - */ - name_end = filename; - de_head++; - num_entries--; - } - } - -# ifndef STAGE1_5 - if (print_possibilities < 0) - return 1; -# endif /* ! STAGE1_5 */ - - errnum = ERR_FILE_NOT_FOUND; - *rest = ch; - return 0; - - found: - *rest = ch; - dirname = rest; - - parent_dir_id = dir_id; - parent_objectid = objectid; - dir_id = deh_dir_id(de_head); - objectid = deh_objectid(de_head); - } -} - -/* - * U-Boot interface functions - */ - -/* - * List given directory - * - * RETURN: 0 - OK, else grub_error_t errnum - */ -int -reiserfs_ls (char *dirname) -{ - char *dir_slash; - int res; - - errnum = 0; - dir_slash = malloc(strlen(dirname) + 1); - if (dir_slash == NULL) { - return ERR_NUMBER_OVERFLOW; - } - strcpy(dir_slash, dirname); - /* add "/" to the directory name */ - strcat(dir_slash, "/"); - - print_possibilities = 1; - res = reiserfs_dir (dir_slash); - free(dir_slash); - if (!res || errnum) { - return errnum; - } - - return 0; -} - -/* - * Open file for reading - * - * RETURN: >0 - OK, size of opened file - * <0 - ERROR -grub_error_t errnum - */ -int -reiserfs_open (char *filename) -{ - /* open the file */ - errnum = 0; - print_possibilities = 0; - if (!reiserfs_dir (filename) || errnum) { - return -errnum; - } - return filemax; -} diff --git a/fs/reiserfs/reiserfs_private.h b/fs/reiserfs/reiserfs_private.h deleted file mode 100644 index 5936f214005..00000000000 --- a/fs/reiserfs/reiserfs_private.h +++ /dev/null @@ -1,509 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README - * - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2000, 2001 Free Software Foundation, Inc. - * - * (C) Copyright 2003 - 2004 - * Sysgo AG, , Pavel Bartusek - * - */ - -/* An implementation for the ReiserFS filesystem ported from GRUB. - * Some parts of this code (mainly the structures and defines) are - * from the original reiser fs code, as found in the linux kernel. - */ - -#include - -#ifndef __BYTE_ORDER -#if defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN) -#define __BYTE_ORDER __LITTLE_ENDIAN -#elif defined(__BIG_ENDIAN) && !defined(__LITTLE_ENDIAN) -#define __BYTE_ORDER __BIG_ENDIAN -#else -#error "unable to define __BYTE_ORDER" -#endif -#endif /* not __BYTE_ORDER */ - -#define FSYS_BUFLEN 0x8000 -#define FSYS_BUF fsys_buf - -/* This is the new super block of a journaling reiserfs system */ -struct reiserfs_super_block -{ - __u32 s_block_count; /* blocks count */ - __u32 s_free_blocks; /* free blocks count */ - __u32 s_root_block; /* root block number */ - __u32 s_journal_block; /* journal block number */ - __u32 s_journal_dev; /* journal device number */ - __u32 s_journal_size; /* size of the journal on FS creation. used to make sure they don't overflow it */ - __u32 s_journal_trans_max; /* max number of blocks in a transaction. */ - __u32 s_journal_magic; /* random value made on fs creation */ - __u32 s_journal_max_batch; /* max number of blocks to batch into a trans */ - __u32 s_journal_max_commit_age; /* in seconds, how old can an async commit be */ - __u32 s_journal_max_trans_age; /* in seconds, how old can a transaction be */ - __u16 s_blocksize; /* block size */ - __u16 s_oid_maxsize; /* max size of object id array */ - __u16 s_oid_cursize; /* current size of object id array */ - __u16 s_state; /* valid or error */ - char s_magic[16]; /* reiserfs magic string indicates that file system is reiserfs */ - __u16 s_tree_height; /* height of disk tree */ - __u16 s_bmap_nr; /* amount of bitmap blocks needed to address each block of file system */ - __u16 s_version; - char s_unused[128]; /* zero filled by mkreiserfs */ -}; - - -#define sb_root_block(sbp) (__le32_to_cpu((sbp)->s_root_block)) -#define sb_journal_block(sbp) (__le32_to_cpu((sbp)->s_journal_block)) -#define set_sb_journal_block(sbp,v) ((sbp)->s_journal_block = __cpu_to_le32(v)) -#define sb_journal_size(sbp) (__le32_to_cpu((sbp)->s_journal_size)) -#define sb_blocksize(sbp) (__le16_to_cpu((sbp)->s_blocksize)) -#define set_sb_blocksize(sbp,v) ((sbp)->s_blocksize = __cpu_to_le16(v)) -#define sb_version(sbp) (__le16_to_cpu((sbp)->s_version)) -#define set_sb_version(sbp,v) ((sbp)->s_version = __cpu_to_le16(v)) - - -#define REISERFS_MAX_SUPPORTED_VERSION 2 -#define REISERFS_SUPER_MAGIC_STRING "ReIsErFs" -#define REISER2FS_SUPER_MAGIC_STRING "ReIsEr2Fs" -#define REISER3FS_SUPER_MAGIC_STRING "ReIsEr3Fs" - -#define MAX_HEIGHT 7 - -/* must be correct to keep the desc and commit structs at 4k */ -#define JOURNAL_TRANS_HALF 1018 - -/* first block written in a commit. */ -struct reiserfs_journal_desc { - __u32 j_trans_id; /* id of commit */ - __u32 j_len; /* length of commit. len +1 is the commit block */ - __u32 j_mount_id; /* mount id of this trans*/ - __u32 j_realblock[JOURNAL_TRANS_HALF]; /* real locations for the first blocks */ - char j_magic[12]; -}; - -/* last block written in a commit */ -struct reiserfs_journal_commit { - __u32 j_trans_id; /* must match j_trans_id from the desc block */ - __u32 j_len; /* ditto */ - __u32 j_realblock[JOURNAL_TRANS_HALF]; /* real locations for the last blocks */ - char j_digest[16]; /* md5 sum of all the blocks involved, including desc and commit. not used, kill it */ -}; - -/* this header block gets written whenever a transaction is considered - fully flushed, and is more recent than the last fully flushed - transaction. - fully flushed means all the log blocks and all the real blocks are - on disk, and this transaction does not need to be replayed. -*/ -struct reiserfs_journal_header { - /* id of last fully flushed transaction */ - __u32 j_last_flush_trans_id; - /* offset in the log of where to start replay after a crash */ - __u32 j_first_unflushed_offset; - /* mount id to detect very old transactions */ - __u32 j_mount_id; -}; - -/* magic string to find desc blocks in the journal */ -#define JOURNAL_DESC_MAGIC "ReIsErLB" - - -/* - * directories use this key as well as old files - */ -struct offset_v1 -{ - /* - * for regular files this is the offset to the first byte of the - * body, contained in the object-item, as measured from the start of - * the entire body of the object. - * - * for directory entries, k_offset consists of hash derived from - * hashing the name and using few bits (23 or more) of the resulting - * hash, and generation number that allows distinguishing names with - * hash collisions. If number of collisions overflows generation - * number, we return EEXIST. High order bit is 0 always - */ - __u32 k_offset; - __u32 k_uniqueness; -}; - -struct offset_v2 { - /* - * for regular files this is the offset to the first byte of the - * body, contained in the object-item, as measured from the start of - * the entire body of the object. - * - * for directory entries, k_offset consists of hash derived from - * hashing the name and using few bits (23 or more) of the resulting - * hash, and generation number that allows distinguishing names with - * hash collisions. If number of collisions overflows generation - * number, we return EEXIST. High order bit is 0 always - */ - -#if defined(__LITTLE_ENDIAN_BITFIELD) - /* little endian version */ - __u64 k_offset:60; - __u64 k_type: 4; -#elif defined(__BIG_ENDIAN_BITFIELD) - /* big endian version */ - __u64 k_type: 4; - __u64 k_offset:60; -#else -#error "__LITTLE_ENDIAN_BITFIELD or __BIG_ENDIAN_BITFIELD must be defined" -#endif -} __attribute__ ((__packed__)); - -#define TYPE_MAXTYPE 3 -#define TYPE_ANY 15 - -#if (__BYTE_ORDER == __BIG_ENDIAN) -typedef union { - struct offset_v2 offset_v2; - __u64 linear; -} __attribute__ ((__packed__)) offset_v2_esafe_overlay; - -static inline __u16 offset_v2_k_type( const struct offset_v2 *v2 ) -{ - offset_v2_esafe_overlay tmp = *(const offset_v2_esafe_overlay *)v2; - tmp.linear = __le64_to_cpu( tmp.linear ); - return (tmp.offset_v2.k_type <= TYPE_MAXTYPE)?tmp.offset_v2.k_type:TYPE_ANY; -} - -static inline loff_t offset_v2_k_offset( const struct offset_v2 *v2 ) -{ - offset_v2_esafe_overlay tmp = *(const offset_v2_esafe_overlay *)v2; - tmp.linear = __le64_to_cpu( tmp.linear ); - return tmp.offset_v2.k_offset; -} -#elif (__BYTE_ORDER == __LITTLE_ENDIAN) -# define offset_v2_k_type(v2) ((v2)->k_type) -# define offset_v2_k_offset(v2) ((v2)->k_offset) -#else -#error "__BYTE_ORDER must be __LITTLE_ENDIAN or __BIG_ENDIAN" -#endif - -struct key -{ - /* packing locality: by default parent directory object id */ - __u32 k_dir_id; - /* object identifier */ - __u32 k_objectid; - /* the offset and node type (old and new form) */ - union - { - struct offset_v1 v1; - struct offset_v2 v2; - } - u; -}; - -#define KEY_SIZE (sizeof (struct key)) - -/* Header of a disk block. More precisely, header of a formatted leaf - or internal node, and not the header of an unformatted node. */ -struct block_head -{ - __u16 blk_level; /* Level of a block in the tree. */ - __u16 blk_nr_item; /* Number of keys/items in a block. */ - __u16 blk_free_space; /* Block free space in bytes. */ - struct key blk_right_delim_key; /* Right delimiting key for this block (supported for leaf level nodes - only) */ -}; -#define BLKH_SIZE (sizeof (struct block_head)) -#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */ - -struct item_head -{ - /* Everything in the tree is found by searching for it based on - * its key.*/ - struct key ih_key; - union { - /* The free space in the last unformatted node of an - indirect item if this is an indirect item. This - equals 0xFFFF iff this is a direct item or stat data - item. Note that the key, not this field, is used to - determine the item type, and thus which field this - union contains. */ - __u16 ih_free_space; - /* Iff this is a directory item, this field equals the - number of directory entries in the directory item. */ - __u16 ih_entry_count; - } __attribute__ ((__packed__)) u; - __u16 ih_item_len; /* total size of the item body */ - __u16 ih_item_location; /* an offset to the item body - * within the block */ - __u16 ih_version; /* 0 for all old items, 2 for new - ones. Highest bit is set by fsck - temporary, cleaned after all - done */ -} __attribute__ ((__packed__)); - -/* size of item header */ -#define IH_SIZE (sizeof (struct item_head)) - -#define ITEM_VERSION_1 0 -#define ITEM_VERSION_2 1 - -#define ih_version(ih) (__le16_to_cpu((ih)->ih_version)) - -#define IH_KEY_OFFSET(ih) (ih_version(ih) == ITEM_VERSION_1 \ - ? __le32_to_cpu((ih)->ih_key.u.v1.k_offset) \ - : offset_v2_k_offset(&((ih)->ih_key.u.v2))) - -#define IH_KEY_ISTYPE(ih, type) (ih_version(ih) == ITEM_VERSION_1 \ - ? __le32_to_cpu((ih)->ih_key.u.v1.k_uniqueness) == V1_##type \ - : offset_v2_k_type(&((ih)->ih_key.u.v2)) == V2_##type) - -/***************************************************************************/ -/* DISK CHILD */ -/***************************************************************************/ -/* Disk child pointer: The pointer from an internal node of the tree - to a node that is on disk. */ -struct disk_child { - __u32 dc_block_number; /* Disk child's block number. */ - __u16 dc_size; /* Disk child's used space. */ - __u16 dc_reserved; -}; - -#define DC_SIZE (sizeof(struct disk_child)) -#define dc_block_number(dc_p) (__le32_to_cpu((dc_p)->dc_block_number)) - - -/* - * old stat data is 32 bytes long. We are going to distinguish new one by - * different size - */ -struct stat_data_v1 -{ - __u16 sd_mode; /* file type, permissions */ - __u16 sd_nlink; /* number of hard links */ - __u16 sd_uid; /* owner */ - __u16 sd_gid; /* group */ - __u32 sd_size; /* file size */ - __u32 sd_atime; /* time of last access */ - __u32 sd_mtime; /* time file was last modified */ - __u32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */ - union { - __u32 sd_rdev; - __u32 sd_blocks; /* number of blocks file uses */ - } __attribute__ ((__packed__)) u; - __u32 sd_first_direct_byte; /* first byte of file which is stored - in a direct item: except that if it - equals 1 it is a symlink and if it - equals ~(__u32)0 there is no - direct item. The existence of this - field really grates on me. Let's - replace it with a macro based on - sd_size and our tail suppression - policy. Someday. -Hans */ -} __attribute__ ((__packed__)); - -#define stat_data_v1(ih) (ih_version(ih) == ITEM_VERSION_1) -#define sd_v1_mode(sdp) ((sdp)->sd_mode) -#define sd_v1_nlink(sdp) (__le16_to_cpu((sdp)->sd_nlink)) -#define sd_v1_uid(sdp) (__le16_to_cpu((sdp)->sd_uid)) -#define sd_v1_gid(sdp) (__le16_to_cpu((sdp)->sd_gid)) -#define sd_v1_size(sdp) (__le32_to_cpu((sdp)->sd_size)) -#define sd_v1_mtime(sdp) (__le32_to_cpu((sdp)->sd_mtime)) - -/* Stat Data on disk (reiserfs version of UFS disk inode minus the - address blocks) */ -struct stat_data { - __u16 sd_mode; /* file type, permissions */ - __u16 sd_attrs; /* persistent inode flags */ - __u32 sd_nlink; /* number of hard links */ - __u64 sd_size; /* file size */ - __u32 sd_uid; /* owner */ - __u32 sd_gid; /* group */ - __u32 sd_atime; /* time of last access */ - __u32 sd_mtime; /* time file was last modified */ - __u32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */ - __u32 sd_blocks; - union { - __u32 sd_rdev; - __u32 sd_generation; - /*__u32 sd_first_direct_byte; */ - /* first byte of file which is stored in a - direct item: except that if it equals 1 - it is a symlink and if it equals - ~(__u32)0 there is no direct item. The - existence of this field really grates - on me. Let's replace it with a macro - based on sd_size and our tail - suppression policy? */ - } __attribute__ ((__packed__)) u; -} __attribute__ ((__packed__)); - -#define stat_data_v2(ih) (ih_version(ih) == ITEM_VERSION_2) -#define sd_v2_mode(sdp) (__le16_to_cpu((sdp)->sd_mode)) -#define sd_v2_nlink(sdp) (__le32_to_cpu((sdp)->sd_nlink)) -#define sd_v2_size(sdp) (__le64_to_cpu((sdp)->sd_size)) -#define sd_v2_uid(sdp) (__le32_to_cpu((sdp)->sd_uid)) -#define sd_v2_gid(sdp) (__le32_to_cpu((sdp)->sd_gid)) -#define sd_v2_mtime(sdp) (__le32_to_cpu((sdp)->sd_mtime)) - -#define sd_mode(sdp) (__le16_to_cpu((sdp)->sd_mode)) -#define sd_size(sdp) (__le32_to_cpu((sdp)->sd_size)) -#define sd_size_hi(sdp) (__le32_to_cpu((sdp)->sd_size_hi)) - -struct reiserfs_de_head -{ - __u32 deh_offset; /* third component of the directory entry key */ - __u32 deh_dir_id; /* objectid of the parent directory of the - object, that is referenced by directory entry */ - __u32 deh_objectid;/* objectid of the object, that is referenced by - directory entry */ - __u16 deh_location;/* offset of name in the whole item */ - __u16 deh_state; /* whether 1) entry contains stat data (for - future), and 2) whether entry is hidden - (unlinked) */ -}; - -#define DEH_SIZE (sizeof (struct reiserfs_de_head)) -#define deh_offset(p_deh) (__le32_to_cpu((p_deh)->deh_offset)) -#define deh_dir_id(p_deh) (__le32_to_cpu((p_deh)->deh_dir_id)) -#define deh_objectid(p_deh) (__le32_to_cpu((p_deh)->deh_objectid)) -#define deh_location(p_deh) (__le16_to_cpu((p_deh)->deh_location)) -#define deh_state(p_deh) (__le16_to_cpu((p_deh)->deh_state)) - - -#define DEH_Statdata (1 << 0) /* not used now */ -#define DEH_Visible (1 << 2) - -#define SD_OFFSET 0 -#define SD_UNIQUENESS 0 -#define DOT_OFFSET 1 -#define DOT_DOT_OFFSET 2 -#define DIRENTRY_UNIQUENESS 500 - -#define V1_TYPE_STAT_DATA 0x0 -#define V1_TYPE_DIRECT 0xffffffff -#define V1_TYPE_INDIRECT 0xfffffffe -#define V1_TYPE_DIRECTORY_MAX 0xfffffffd -#define V2_TYPE_STAT_DATA 0 -#define V2_TYPE_INDIRECT 1 -#define V2_TYPE_DIRECT 2 -#define V2_TYPE_DIRENTRY 3 - -#define REISERFS_ROOT_OBJECTID 2 -#define REISERFS_ROOT_PARENT_OBJECTID 1 -#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024) -/* the spot for the super in versions 3.5 - 3.5.11 (inclusive) */ -#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024) -#define REISERFS_OLD_BLOCKSIZE 4096 - -#define S_ISREG(mode) (((mode) & 0170000) == 0100000) -#define S_ISDIR(mode) (((mode) & 0170000) == 0040000) -#define S_ISLNK(mode) (((mode) & 0170000) == 0120000) - -#define PATH_MAX 1024 /* include/linux/limits.h */ -#define MAX_LINK_COUNT 5 /* number of symbolic links to follow */ - -/* The size of the node cache */ -#define FSYSREISER_CACHE_SIZE 24*1024 -#define FSYSREISER_MIN_BLOCKSIZE SECTOR_SIZE -#define FSYSREISER_MAX_BLOCKSIZE FSYSREISER_CACHE_SIZE / 3 - -/* Info about currently opened file */ -struct fsys_reiser_fileinfo -{ - __u32 k_dir_id; - __u32 k_objectid; -}; - -/* In memory info about the currently mounted filesystem */ -struct fsys_reiser_info -{ - /* The last read item head */ - struct item_head *current_ih; - /* The last read item */ - char *current_item; - /* The information for the currently opened file */ - struct fsys_reiser_fileinfo fileinfo; - /* The start of the journal */ - __u32 journal_block; - /* The size of the journal */ - __u32 journal_block_count; - /* The first valid descriptor block in journal - (relative to journal_block) */ - __u32 journal_first_desc; - - /* The ReiserFS version. */ - __u16 version; - /* The current depth of the reiser tree. */ - __u16 tree_depth; - /* SECTOR_SIZE << blocksize_shift == blocksize. */ - __u8 blocksize_shift; - /* 1 << full_blocksize_shift == blocksize. */ - __u8 fullblocksize_shift; - /* The reiserfs block size (must be a power of 2) */ - __u16 blocksize; - /* The number of cached tree nodes */ - __u16 cached_slots; - /* The number of valid transactions in journal */ - __u16 journal_transactions; - - unsigned int blocks[MAX_HEIGHT]; - unsigned int next_key_nr[MAX_HEIGHT]; -}; - -/* The cached s+tree blocks in FSYS_BUF, see below - * for a more detailed description. - */ -#define ROOT ((char *) ((int) FSYS_BUF)) -#define CACHE(i) (ROOT + ((i) << INFO->fullblocksize_shift)) -#define LEAF CACHE (DISK_LEAF_NODE_LEVEL) - -#define BLOCKHEAD(cache) ((struct block_head *) cache) -#define ITEMHEAD ((struct item_head *) ((int) LEAF + BLKH_SIZE)) -#define KEY(cache) ((struct key *) ((int) cache + BLKH_SIZE)) -#define DC(cache) ((struct disk_child *) \ - ((int) cache + BLKH_SIZE + KEY_SIZE * nr_item)) -/* The fsys_reiser_info block. - */ -#define INFO \ - ((struct fsys_reiser_info *) ((int) FSYS_BUF + FSYSREISER_CACHE_SIZE)) -/* - * The journal cache. For each transaction it contains the number of - * blocks followed by the real block numbers of this transaction. - * - * If the block numbers of some transaction won't fit in this space, - * this list is stopped with a 0xffffffff marker and the remaining - * uncommitted transactions aren't cached. - */ -#define JOURNAL_START ((__u32 *) (INFO + 1)) -#define JOURNAL_END ((__u32 *) (FSYS_BUF + FSYS_BUFLEN)) - - -static __inline__ unsigned long -log2 (unsigned long word) -{ -#ifdef __I386__ - __asm__ ("bsfl %1,%0" - : "=r" (word) - : "r" (word)); - return word; -#else - int i; - - for(i=0; i<(8*sizeof(word)); i++) - if ((1< - * Pavel Bartusek - */ - -/* An implementation for the ReiserFS filesystem ported from GRUB. - * Some parts of this code (mainly the structures and defines) are - * from the original reiser fs code, as found in the linux kernel. - */ - - -#define SECTOR_SIZE 0x200 -#define SECTOR_BITS 9 - -struct blk_desc; -struct disk_partition; - -/* Error codes */ -typedef enum -{ - ERR_NONE = 0, - ERR_BAD_FILENAME, - ERR_BAD_FILETYPE, - ERR_BAD_GZIP_DATA, - ERR_BAD_GZIP_HEADER, - ERR_BAD_PART_TABLE, - ERR_BAD_VERSION, - ERR_BELOW_1MB, - ERR_BOOT_COMMAND, - ERR_BOOT_FAILURE, - ERR_BOOT_FEATURES, - ERR_DEV_FORMAT, - ERR_DEV_VALUES, - ERR_EXEC_FORMAT, - ERR_FILELENGTH, - ERR_FILE_NOT_FOUND, - ERR_FSYS_CORRUPT, - ERR_FSYS_MOUNT, - ERR_GEOM, - ERR_NEED_LX_KERNEL, - ERR_NEED_MB_KERNEL, - ERR_NO_DISK, - ERR_NO_PART, - ERR_NUMBER_PARSING, - ERR_OUTSIDE_PART, - ERR_READ, - ERR_SYMLINK_LOOP, - ERR_UNRECOGNIZED, - ERR_WONT_FIT, - ERR_WRITE, - ERR_BAD_ARGUMENT, - ERR_UNALIGNED, - ERR_PRIVILEGED, - ERR_DEV_NEED_INIT, - ERR_NO_DISK_SPACE, - ERR_NUMBER_OVERFLOW, - - MAX_ERR_NUM -} reiserfs_error_t; - - -void reiserfs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info); -extern int reiserfs_ls (char *dirname); -extern int reiserfs_open (char *filename); -extern int reiserfs_read (char *buf, unsigned len); -extern int reiserfs_mount (unsigned part_length); -- cgit v1.3.1 From 407184cd636d5ef7a5b118e6df6f06d86432e1eb Mon Sep 17 00:00:00 2001 From: Ivan Orlov Date: Fri, 23 Feb 2024 17:14:20 +0000 Subject: cmd: eeprom: Fix config dependency We should have CONFIG_DM_I2C or CONFIG_SYS_I2C_LEGACY enabled in order for `cmd/eeprom.c` to compile as it depends on the i2c functions which are not compiled otherwise. Update the Kconfig entry for the 'eeprom' command correspondingly. Signed-off-by: Ivan Orlov Reviewed-by: Tom Rini --- cmd/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 438c6d1c480..3d204edfa3f 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -740,6 +740,7 @@ config CRC32_VERIFY config CMD_EEPROM bool "eeprom - EEPROM subsystem" + depends on DM_I2C || SYS_I2C_LEGACY help (deprecated, needs conversion to driver model) Provides commands to read and write EEPROM (Electrically Erasable -- cgit v1.3.1 From 6ec3f9208948b4f3aa4b6d8362c0daaffaea0a0f Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Sat, 2 Mar 2024 16:05:48 +0100 Subject: cmd: md5sum: use hash_command Drop old implementation and use hash_command() instead, as how it's currently done for crc32 and sha1sum cmds. Test: => md5sum 0x60000000 0x200 md5 for 60000000 ... 600001ff ==> e6bbbe95f5b41996f4a9b9af7bbd4050 Signed-off-by: Igor Opaniuk --- cmd/Kconfig | 1 + cmd/md5sum.c | 150 ++++------------------------------------------------------ common/hash.c | 8 ++-- 3 files changed, 16 insertions(+), 143 deletions(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 3d204edfa3f..102f62ac89d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -826,6 +826,7 @@ config LOOPW config CMD_MD5SUM bool "md5sum" select MD5 + select HASH help Compute MD5 checksum. diff --git a/cmd/md5sum.c b/cmd/md5sum.c index 0f0e1d3dd68..ded3f9e1831 100644 --- a/cmd/md5sum.c +++ b/cmd/md5sum.c @@ -7,166 +7,36 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */ -#include #include #include #include +#include #include #include #include -/* - * Store the resulting sum to an address or variable - */ -static void store_result(const u8 *sum, const char *dest) -{ - unsigned int i; - - if (*dest == '*') { - u8 *ptr; - - ptr = (u8 *)hextoul(dest + 1, NULL); - for (i = 0; i < 16; i++) - *ptr++ = sum[i]; - } else { - char str_output[33]; - char *str_ptr = str_output; - - for (i = 0; i < 16; i++) { - sprintf(str_ptr, "%02x", sum[i]); - str_ptr += 2; - } - env_set(dest, str_output); - } -} - -#ifdef CONFIG_MD5SUM_VERIFY -static int parse_verify_sum(char *verify_str, u8 *vsum) -{ - if (*verify_str == '*') { - u8 *ptr; - - ptr = (u8 *)hextoul(verify_str + 1, NULL); - memcpy(vsum, ptr, 16); - } else { - unsigned int i; - char *vsum_str; - - if (strlen(verify_str) == 32) - vsum_str = verify_str; - else { - vsum_str = env_get(verify_str); - if (vsum_str == NULL || strlen(vsum_str) != 32) - return 1; - } - - for (i = 0; i < 16; i++) { - char *nullp = vsum_str + (i + 1) * 2; - char end = *nullp; - - *nullp = '\0'; - *(u8 *)(vsum + i) = - hextoul(vsum_str + (i * 2), NULL); - *nullp = end; - } - } - return 0; -} - -int do_md5sum(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +static int do_md5sum(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) { - ulong addr, len; - unsigned int i; - u8 output[16]; - u8 vsum[16]; - int verify = 0; + int flags = HASH_FLAG_ENV; int ac; - char * const *av; - void *buf; + char *const *av; if (argc < 3) return CMD_RET_USAGE; av = argv + 1; ac = argc - 1; - if (strcmp(*av, "-v") == 0) { - verify = 1; + if (IS_ENABLED(CONFIG_MD5SUM_VERIFY) && strcmp(*av, "-v") == 0) { + flags |= HASH_FLAG_VERIFY; av++; ac--; - if (ac < 3) - return CMD_RET_USAGE; } - addr = hextoul(*av++, NULL); - len = hextoul(*av++, NULL); - - buf = map_sysmem(addr, len); - md5_wd(buf, len, output, CHUNKSZ_MD5); - unmap_sysmem(buf); - - if (!verify) { - printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1); - for (i = 0; i < 16; i++) - printf("%02x", output[i]); - printf("\n"); - - if (ac > 2) - store_result(output, *av); - } else { - char *verify_str = *av++; - - if (parse_verify_sum(verify_str, vsum)) { - printf("ERROR: %s does not contain a valid md5 sum\n", - verify_str); - return 1; - } - if (memcmp(output, vsum, 16) != 0) { - printf("md5 for %08lx ... %08lx ==> ", addr, - addr + len - 1); - for (i = 0; i < 16; i++) - printf("%02x", output[i]); - printf(" != "); - for (i = 0; i < 16; i++) - printf("%02x", vsum[i]); - printf(" ** ERROR **\n"); - return 1; - } - } - - return 0; -} -#else -static int do_md5sum(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) -{ - unsigned long addr, len; - unsigned int i; - u8 output[16]; - void *buf; - - if (argc < 3) - return CMD_RET_USAGE; - - addr = hextoul(argv[1], NULL); - len = hextoul(argv[2], NULL); - - buf = map_sysmem(addr, len); - md5_wd(buf, len, output, CHUNKSZ_MD5); - unmap_sysmem(buf); - - printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1); - for (i = 0; i < 16; i++) - printf("%02x", output[i]); - printf("\n"); - - if (argc > 3) - store_result(output, argv[3]); - - return 0; + return hash_command("md5", flags, cmdtp, flag, ac, av); } -#endif -#ifdef CONFIG_MD5SUM_VERIFY +#if IS_ENABLED(CONFIG_MD5SUM_VERIFY) U_BOOT_CMD( md5sum, 5, 1, do_md5sum, "compute MD5 message digest", @@ -182,4 +52,4 @@ U_BOOT_CMD( "address count [[*]sum]\n" " - compute MD5 message digest [save to sum]" ); -#endif +#endif /* IS_ENABLED(CONFIG_MD5SUM_VERIFY) */ diff --git a/common/hash.c b/common/hash.c index e837c56d443..3d6b84de473 100644 --- a/common/hash.c +++ b/common/hash.c @@ -321,7 +321,8 @@ static struct hash_algo hash_algo[] = { /* Try to minimize code size for boards that don't want much hashing */ #if CONFIG_IS_ENABLED(SHA256) || IS_ENABLED(CONFIG_CMD_SHA1SUM) || \ CONFIG_IS_ENABLED(CRC32_VERIFY) || IS_ENABLED(CONFIG_CMD_HASH) || \ - CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512) + CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512) || \ + IS_ENABLED(CONFIG_CMD_MD5SUM) #define multi_hash() 1 #else #define multi_hash() 0 @@ -404,7 +405,8 @@ int hash_block(const char *algo_name, const void *data, unsigned int len, } #if !defined(CONFIG_SPL_BUILD) && (defined(CONFIG_CMD_HASH) || \ - defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)) + defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)) || \ + defined(CONFIG_CMD_MD5SUM) /** * store_result: Store the resulting sum to an address or variable * @@ -565,7 +567,7 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp, /* Try to avoid code bloat when verify is not needed */ #if defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_SHA1SUM_VERIFY) || \ - defined(CONFIG_HASH_VERIFY) + defined(CONFIG_MD5SUM_VERIFY) || defined(CONFIG_HASH_VERIFY) if (flags & HASH_FLAG_VERIFY) { #else if (0) { -- cgit v1.3.1 From 9a6e975c7c41f2fb67d7ef11fceb28942a4a4b4c Mon Sep 17 00:00:00 2001 From: Weizhao Ouyang Date: Mon, 4 Mar 2024 14:42:42 +0000 Subject: cmd: rng: Add rng list command The 'rng list' command probes all RNG devices and list those devices that are successfully probed. Also update the help info. Reviewed-by: Heinrich Schuchardt Signed-off-by: Weizhao Ouyang --- cmd/rng.c | 23 ++++++++++++++++++----- doc/usage/cmd/rng.rst | 14 ++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'cmd') diff --git a/cmd/rng.c b/cmd/rng.c index 52f722c7af8..b073a6c8492 100644 --- a/cmd/rng.c +++ b/cmd/rng.c @@ -19,6 +19,22 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) struct udevice *dev; int ret = CMD_RET_SUCCESS; + if (argc == 2 && !strcmp(argv[1], "list")) { + int idx = 0; + + uclass_foreach_dev_probe(UCLASS_RNG, dev) { + idx++; + printf("RNG #%d - %s\n", dev->seq_, dev->name); + } + + if (!idx) { + log_err("No RNG device\n"); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; + } + switch (argc) { case 1: devnum = 0; @@ -56,12 +72,9 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return ret; } -U_BOOT_LONGHELP(rng, - "[dev [n]]\n" - " - print n random bytes(max 64) read from dev\n"); - U_BOOT_CMD( rng, 3, 0, do_rng, "print bytes from the hardware random number generator", - rng_help_text + "list - list all the probed rng devices\n" + "rng [dev] [n] - print n random bytes(max 64) read from dev\n" ); diff --git a/doc/usage/cmd/rng.rst b/doc/usage/cmd/rng.rst index 274e4d88df3..4a61e33d272 100644 --- a/doc/usage/cmd/rng.rst +++ b/doc/usage/cmd/rng.rst @@ -11,16 +11,22 @@ Synopsis :: - rng [devnum [n]] + rng list + rng [dev] [n] -Description ------------ +rng list +-------- + +List all the probed rng devices. + +rng [dev] [n] +------------- The *rng* command reads the random number generator(RNG) device and prints the random bytes read on the console. A maximum of 64 bytes can be read in one invocation of the command. -devnum +dev The RNG device from which the random bytes are to be read. Defaults to 0. -- cgit v1.3.1 From 421359ac52bfc80946929c4ffeacf6a68273e758 Mon Sep 17 00:00:00 2001 From: Hanyuan Zhao Date: Tue, 5 Mar 2024 15:37:35 +0800 Subject: cli: allow users to determine history buffer allocation method This commit allows users to choose the appropriate memory allocation method between static allocated and dynamically calloc. The previous static-array way will not obviously contribute to the final binary size since it is uninitialized, and might have better performance than the dynamical one. Now we provide the users with both the two options. Signed-off-by: Hanyuan Zhao --- cmd/Kconfig | 11 +++++++++++ common/cli_readline.c | 36 +++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 11 deletions(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 102f62ac89d..bd5464a4989 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -189,6 +189,17 @@ config CMD_HISTORY Show the command-line history, i.e. a list of commands that are in the history buffer. +config CMD_HISTORY_USE_CALLOC + bool "dynamically allocate memory" + default y + depends on CMD_HISTORY + help + Saying Y to this will use calloc to get the space for history + storing. Otherwise the history buffer will be an uninitialized + static array directly, without the memory allocation, and it is + writable after relocation to RAM. If u-boot is running from ROM + all the time or unsure, say Y to this. + config CMD_LICENSE bool "license" select BUILD_BIN2C diff --git a/common/cli_readline.c b/common/cli_readline.c index 99e7efdfe55..cf4339d0e50 100644 --- a/common/cli_readline.c +++ b/common/cli_readline.c @@ -86,6 +86,9 @@ static int hist_add_idx; static int hist_cur = -1; static unsigned hist_num; +#ifndef CONFIG_CMD_HISTORY_USE_CALLOC +static char hist_data[HIST_MAX][HIST_SIZE + 1]; +#endif static char *hist_list[HIST_MAX]; #define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1) @@ -100,20 +103,26 @@ static void getcmd_putchars(int count, int ch) static int hist_init(void) { - unsigned char *hist; int i; - hist_max = 0; - hist_add_idx = 0; - hist_cur = -1; - hist_num = 0; - - hist = calloc(HIST_MAX, HIST_SIZE + 1); +#ifndef CONFIG_CMD_HISTORY_USE_CALLOC + for (i = 0; i < HIST_MAX; i++) { + hist_list[i] = hist_data[i]; + hist_list[i][0] = '\0'; + } +#else + unsigned char *hist = calloc(HIST_MAX, HIST_SIZE + 1); if (!hist) panic("%s: calloc: out of memory!\n", __func__); for (i = 0; i < HIST_MAX; i++) hist_list[i] = hist + (i * (HIST_SIZE + 1)); +#endif + + hist_max = 0; + hist_add_idx = 0; + hist_cur = -1; + hist_num = 0; return 0; } @@ -643,10 +652,15 @@ int cli_readline_into_buffer(const char *const prompt, char *buffer, static int initted; /* - * History uses a global array which is not - * writable until after relocation to RAM. - * Revert to non-history version if still - * running from flash. + * Say N to CMD_HISTORY_USE_CALLOC will skip runtime + * allocation for the history buffer and directly + * use an uninitialized static array as the buffer. + * Doing this might have better performance and not + * increase the binary file's size, as it only marks + * the size. However, the array is only writable after + * relocation to RAM. If u-boot is running from ROM + * all the time, consider say Y to CMD_HISTORY_USE_CALLOC + * or disable CMD_HISTORY. */ if (IS_ENABLED(CONFIG_CMDLINE_EDITING) && (gd->flags & GD_FLG_RELOC)) { if (!initted) { -- cgit v1.3.1 From 6d1734f0056720c51a3907ece934a5fbb0fbb0cb Mon Sep 17 00:00:00 2001 From: Maxim Moskalets Date: Fri, 8 Mar 2024 00:29:14 +0300 Subject: cmd: add FDT setup for bootelf by flag Added the ability to use FDT for ELF applications, required to run some OS. To make FDT setup, you need to set the -d fdt_addr_r cmd option for bootelf command. Enable by selecting CMD_ELF_FDT_SETUP. Signed-off-by: Maxim Moskalets --- cmd/Kconfig | 11 +++++++++++ cmd/elf.c | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index bd5464a4989..61e280fb1a4 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -490,6 +490,17 @@ config CMD_ELF help Boot an ELF/vxWorks image from the memory. +config CMD_ELF_FDT_SETUP + bool "Flattened Device Tree setup in bootelf cmd" + default n + depends on CMD_ELF + select LIB_LIBFDT + select LMB + help + Do FDT setup in bootelf command optionally by param -d, which + allows to bring additional system info (e.g. /memory node) to + the Operating System or application. + config CMD_FDT bool "Flattened Device Tree utility commands" default y diff --git a/cmd/elf.c b/cmd/elf.c index b7b9f506a52..df4354d3742 100644 --- a/cmd/elf.c +++ b/cmd/elf.c @@ -38,6 +38,10 @@ static unsigned long do_bootelf_exec(ulong (*entry)(int, char * const[]), /* Interpreter command to boot an arbitrary ELF image from memory */ int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { +#if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) + struct bootm_headers img = {0}; + unsigned long fdt_addr = 0; /* Address of the FDT */ +#endif unsigned long addr; /* Address of the ELF image */ unsigned long rc; /* Return value from user code */ char *sload = NULL; @@ -46,13 +50,25 @@ int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) /* Consume 'bootelf' */ argc--; argv++; - /* Check for flag. */ + /* Check for [-p|-s] flag. */ if (argc >= 1 && (argv[0][0] == '-' && \ (argv[0][1] == 'p' || argv[0][1] == 's'))) { sload = argv[0]; /* Consume flag. */ argc--; argv++; } + +#if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) + /* Check for [-d fdt_addr_r] option. */ + if ((argc >= 2) && (argv[0][0] == '-') && (argv[0][1] == 'd')) { + if (strict_strtoul(argv[1], 16, &fdt_addr) != 0) + return CMD_RET_USAGE; + /* Consume option. */ + argc -= 2; + argv += 2; + } +#endif + /* Check for address. */ if (argc >= 1 && strict_strtoul(argv[0], 16, &addr) != -EINVAL) { /* Consume address */ @@ -68,6 +84,16 @@ int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) else addr = load_elf_image_shdr(addr); +#if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) + if (fdt_addr) { + printf("## Setting up FDT at 0x%08lx ...\n", fdt_addr); + flush(); + + if (image_setup_libfdt(&img, (void *)fdt_addr, NULL)) + return 1; + } +#endif + if (!env_get_autostart()) return rcode; @@ -298,9 +324,16 @@ int do_bootvx(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD( bootelf, CONFIG_SYS_MAXARGS, 0, do_bootelf, "Boot from an ELF image in memory", - "[-p|-s] [address]\n" + "[-p|-s] " +#if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) + "[-d fdt_addr_r] " +#endif + "[address]\n" "\t- load ELF image at [address] via program headers (-p)\n" - "\t or via section headers (-s)" + "\t or via section headers (-s)\n" +#if CONFIG_IS_ENABLED(CMD_ELF_FDT_SETUP) + "\t- setup FDT image at [fdt_addr_r] (-d)" +#endif ); U_BOOT_CMD( -- cgit v1.3.1 From 808156189b92be4dcbf021b1c2ad75ef3ba45c2c Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Thu, 14 Mar 2024 10:36:19 +0100 Subject: pmic: reword help text Reword the help text for the pmic read and pmic write commands to better match what's expected from the user. Cc: Quentin Schulz Reviewed-by: Kever Yang Signed-off-by: Quentin Schulz --- cmd/pmic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/pmic.c b/cmd/pmic.c index 49a405fa297..c9e9730adf9 100644 --- a/cmd/pmic.c +++ b/cmd/pmic.c @@ -225,6 +225,6 @@ U_BOOT_CMD(pmic, CONFIG_SYS_MAXARGS, 1, do_pmic, "list - list pmic devices\n" "pmic dev [name] - show or [set] operating PMIC device\n" "pmic dump - dump registers\n" - "pmic read address - read byte of register at address\n" - "pmic write address - write byte to register at address\n" + "pmic read - read byte of 'reg' register\n" + "pmic write - write 'byte' byte to 'reg' register\n" ); -- cgit v1.3.1 From 4735d03a9777e96829540adaac28db6a1649620d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 21 Jan 2024 12:52:48 +0100 Subject: acpi: rename aslc_id, aslc_revision The fields Creator ID and Creator Revision contain information about the tool that created an ACPI table. This may be the ASL compiler for some tables but it is not for others. Naming these fields aslc_id and aslc_revision is misleading. It is usual to see diverse values of Creator ID. On a laptop I saw these: 'AMD ', 'INTL, 'MSFT', 'PTEC'. Obviously not all relate to the Intel ASL compiler. Signed-off-by: Heinrich Schuchardt --- arch/x86/lib/acpi_nhlt.c | 2 +- arch/x86/lib/acpi_table.c | 8 ++++---- cmd/acpi.c | 2 +- include/acpi/acpi_table.h | 6 +++--- lib/acpi/acpi_table.c | 4 ++-- lib/acpi/ssdt.c | 2 +- test/dm/acpi.c | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) (limited to 'cmd') diff --git a/arch/x86/lib/acpi_nhlt.c b/arch/x86/lib/acpi_nhlt.c index 6c8cd83e12d..08e13fdea67 100644 --- a/arch/x86/lib/acpi_nhlt.c +++ b/arch/x86/lib/acpi_nhlt.c @@ -409,7 +409,7 @@ int nhlt_serialise_oem_overrides(struct acpi_ctx *ctx, struct nhlt *nhlt, memcpy(header->oem_table_id, oem_table_id, oem_table_id_len); } header->oem_revision = oem_revision; - memcpy(header->aslc_id, ASLC_ID, 4); + memcpy(header->creator_id, ASLC_ID, 4); cur.buf = (void *)(header + 1); cur.start = (void *)header; diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index 5ecd3d4b651..a5683132b01 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -253,7 +253,7 @@ static int acpi_write_tpm2(struct acpi_ctx *ctx, /* Fill out header fields. */ acpi_fill_header(header, "TPM2"); - memcpy(header->aslc_id, ASLC_ID, 4); + memcpy(header->creator_id, ASLC_ID, 4); header->length = sizeof(struct acpi_tpm2); header->revision = acpi_get_table_revision(ACPITAB_TPM2); @@ -479,7 +479,7 @@ static int acpi_create_hpet(struct acpi_hpet *hpet) /* Fill out header fields. */ acpi_fill_header(header, "HPET"); - header->aslc_revision = ASL_REVISION; + header->creator_revision = ASL_REVISION; header->length = sizeof(struct acpi_hpet); header->revision = acpi_get_table_revision(ACPITAB_HPET); @@ -569,8 +569,8 @@ void acpi_fadt_common(struct acpi_fadt *fadt, struct acpi_facs *facs, header->revision = 4; memcpy(header->oem_id, OEM_ID, 6); memcpy(header->oem_table_id, OEM_TABLE_ID, 8); - memcpy(header->aslc_id, ASLC_ID, 4); - header->aslc_revision = 1; + memcpy(header->creator_id, ASLC_ID, 4); + header->creator_revision = 1; fadt->x_firmware_ctrl = map_to_sysmem(facs); fadt->x_dsdt = map_to_sysmem(dsdt); diff --git a/cmd/acpi.c b/cmd/acpi.c index 65caaa5c98e..928e5dc525e 100644 --- a/cmd/acpi.c +++ b/cmd/acpi.c @@ -32,7 +32,7 @@ static void dump_hdr(struct acpi_table_header *hdr) if (has_hdr) { printf(" v%02d %.6s %.8s %x %.4s %x\n", hdr->revision, hdr->oem_id, hdr->oem_table_id, hdr->oem_revision, - hdr->aslc_id, hdr->aslc_revision); + hdr->creator_id, hdr->creator_revision); } else { printf("\n"); } diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index e67562ef654..8256af6d29e 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -57,8 +57,8 @@ struct __packed acpi_table_header { char oem_id[6]; /* OEM identification */ char oem_table_id[8]; /* OEM table identification */ u32 oem_revision; /* OEM revision number */ - char aslc_id[4]; /* ASL compiler vendor ID */ - u32 aslc_revision; /* ASL compiler revision number */ + char creator_id[4]; /* ASL compiler vendor ID */ + u32 creator_revision; /* ASL compiler revision number */ }; struct acpi_gen_regaddr { @@ -831,7 +831,7 @@ void acpi_create_dbg2(struct acpi_dbg2_header *dbg2, /** * acpi_fill_header() - Set up a new table header * - * This sets all fields except length, revision, checksum and aslc_revision + * This sets all fields except length, revision, checksum and creator_revision * * @header: ACPI header to update * @signature: Table signature to use (4 characters) diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 39dd53ec402..c16ead6a6ec 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -116,7 +116,7 @@ void acpi_fill_header(struct acpi_table_header *header, char *signature) memcpy(header->oem_id, OEM_ID, 6); memcpy(header->oem_table_id, OEM_TABLE_ID, 8); header->oem_revision = OEM_REVISION; - memcpy(header->aslc_id, ASLC_ID, 4); + memcpy(header->creator_id, ASLC_ID, 4); } void acpi_align(struct acpi_ctx *ctx) @@ -219,7 +219,7 @@ void acpi_create_dbg2(struct acpi_dbg2_header *dbg2, header->revision = acpi_get_table_revision(ACPITAB_DBG2); acpi_fill_header(header, "DBG2"); - header->aslc_revision = ASL_REVISION; + header->creator_revision = ASL_REVISION; /* One debug device defined */ dbg2->devices_offset = sizeof(struct acpi_dbg2_header); diff --git a/lib/acpi/ssdt.c b/lib/acpi/ssdt.c index b0a96f846e3..e032e266b3c 100644 --- a/lib/acpi/ssdt.c +++ b/lib/acpi/ssdt.c @@ -23,7 +23,7 @@ int acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) acpi_fill_header(ssdt, "SSDT"); ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT); - ssdt->aslc_revision = 1; + ssdt->creator_revision = 1; ssdt->length = sizeof(struct acpi_table_header); acpi_inc(ctx, sizeof(struct acpi_table_header)); diff --git a/test/dm/acpi.c b/test/dm/acpi.c index c53ebcdb1c1..f14b3962f84 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -237,7 +237,7 @@ static int dm_test_acpi_fill_header(struct unit_test_state *uts) hdr.length = 0x11; hdr.revision = 0x22; hdr.checksum = 0x33; - hdr.aslc_revision = 0x44; + hdr.creator_revision = 0x44; acpi_fill_header(&hdr, "ABCD"); ut_asserteq_mem("ABCD", hdr.signature, sizeof(hdr.signature)); @@ -248,8 +248,8 @@ static int dm_test_acpi_fill_header(struct unit_test_state *uts) ut_asserteq_mem(OEM_TABLE_ID, hdr.oem_table_id, sizeof(hdr.oem_table_id)); ut_asserteq(OEM_REVISION, hdr.oem_revision); - ut_asserteq_mem(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id)); - ut_asserteq(0x44, hdr.aslc_revision); + ut_asserteq_mem(ASLC_ID, hdr.creator_id, sizeof(hdr.creator_id)); + ut_asserteq(0x44, hdr.creator_revision); return 0; } -- cgit v1.3.1 From 23109d0575bd9bd96ff0c0dabc00668bebc78239 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 10 Feb 2024 12:06:47 +0100 Subject: cmd: smbios: type 1 wake-up time, family Correct type 1 output * render wake up time as string * print family string * remove duplicate serial number output Signed-off-by: Heinrich Schuchardt --- cmd/smbios.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/smbios.c b/cmd/smbios.c index 66f6b761378..d3bd8b12a67 100644 --- a/cmd/smbios.c +++ b/cmd/smbios.c @@ -14,6 +14,18 @@ DECLARE_GLOBAL_DATA_PTR; +static const char * const wakeup_type_strings[] = { + "Reserved", /* 0x00 */ + "Other", /* 0x01 */ + "Unknown", /* 0x02 */ + "APM Timer", /* 0x03 */ + "Modem Ring", /* 0x04 */ + "Lan Remote", /* 0x05 */ + "Power Switch", /* 0x06 */ + "PCI PME#", /* 0x07 */ + "AC Power Restored", /* 0x08 */ +}; + /** * smbios_get_string() - get SMBIOS string from table * @@ -72,6 +84,14 @@ void smbios_print_str(const char *label, void *table, u8 index) printf("\t%s: %s\n", label, smbios_get_string(table, index)); } +const char *smbios_wakeup_type_str(u8 wakeup_type) +{ + if (wakeup_type >= ARRAY_SIZE(wakeup_type_strings)) + /* Values over 0x08 are reserved. */ + wakeup_type = 0; + return wakeup_type_strings[wakeup_type]; +} + static void smbios_print_type1(struct smbios_type1 *table) { printf("System Information\n"); @@ -81,11 +101,12 @@ static void smbios_print_type1(struct smbios_type1 *table) smbios_print_str("Serial Number", table, table->serial_number); if (table->length >= 0x19) { printf("\tUUID: %pUl\n", table->uuid); - smbios_print_str("Wake Up Type", table, table->serial_number); + printf("\tWake-up Type: %s\n", + smbios_wakeup_type_str(table->wakeup_type)); } if (table->length >= 0x1b) { - smbios_print_str("Serial Number", table, table->serial_number); smbios_print_str("SKU Number", table, table->sku_number); + smbios_print_str("Family", table, table->family); } } -- cgit v1.3.1