Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
a5f340ed3c
!53 backport add loongarch CPU support
From: @li_yunq 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2024-09-20 03:42:15 +00:00
liyunqing_kl
b9a809b32c backport: Support Loongarch CPU 2024-09-20 11:13:15 +08:00
openeuler-ci-bot
75fa181cbe
!48 backport: Use read_file instead of mem_chunk
From: @li_yunq 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2024-09-14 02:04:37 +00:00
liyunqing_kl
89c9b2758e backport: Use read_file instead of mem_chunk 2024-09-12 10:15:51 +08:00
openeuler-ci-bot
36175ef37d
!43 upgrade to 3.5
From: @ni-cunshu 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2024-02-05 08:59:04 +00:00
Ni Cunshu
1c28f99857 upgrade to 3.5
Signed-off-by: Ni Cunshu <nicunshu@huawei.com>
2024-02-05 16:41:37 +08:00
openeuler-ci-bot
a87b20b9f8
!38 backport: Fix segmentation fault in dmi_hp_240_attr()
From: @lvgenggeng 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2023-12-14 11:37:55 +00:00
lvgenggeng
273622b04d backport: Fix segmentation fault in dmi_hp_240_attr()
Signed-off-by: lvgenggeng <lvgenggeng@uniontech.com>
2023-12-14 16:30:26 +08:00
openeuler-ci-bot
c73e4a38b0
!37 Init support for ppc64le
From: @jiahua-yu 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
2023-12-14 08:05:44 +00:00
jiahua.yu
6ba50123bc init support for arch ppc64le 2023-12-14 10:04:23 +08:00
9 changed files with 187 additions and 513 deletions

View File

@ -0,0 +1,64 @@
From c76ddda0ba0aa99a55945e3290095c2ec493c892 Mon Sep 17 00:00:00 2001
From: Jean Delvare <jdelvare@suse.de>
Date: Wed, 26 Apr 2023 15:44:27 +0200
Subject: [PATCH] Consistently use read_file() when reading from a dump file
Use read_file() instead of mem_chunk() to read the entry point from a
dump file. This is faster, and consistent with how we then read the
actual DMI table from that dump file.
This made no functional difference so far, which is why it went
unnoticed for years. But now that a file type check was added to the
mem_chunk() function, we must stop using it to read from regular
files.
This will again allow root to use the --from-dump option.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Tested-by: Jerry Hoemann <jerry.hoemann@hpe.com>
---
dmidecode.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/dmidecode.c b/dmidecode.c
index 54f59c1..52ddbf1 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -6025,17 +6025,25 @@ int main(int argc, char * const argv[])
pr_comment("dmidecode %s", VERSION);
/* Read from dump if so instructed */
+ size = 0x20;
if (opt.flags & FLAG_FROM_DUMP)
{
if (!(opt.flags & FLAG_QUIET))
pr_info("Reading SMBIOS/DMI data from file %s.",
opt.dumpfile);
- if ((buf = mem_chunk(0, 0x20, opt.dumpfile)) == NULL)
+ if ((buf = read_file(0, &size, opt.dumpfile)) == NULL)
{
ret = 1;
goto exit_free;
}
+ /* Truncated entry point can't be processed */
+ if (size < 0x20)
+ {
+ ret = 1;
+ goto done;
+ }
+
if (memcmp(buf, "_SM3_", 5) == 0)
{
if (smbios3_decode(buf, opt.dumpfile, 0))
@@ -6059,7 +6067,6 @@ int main(int argc, char * const argv[])
* contain one of several types of entry points, so read enough for
* the largest one, then determine what type it contains.
*/
- size = 0x20;
if (!(opt.flags & FLAG_NO_SYSFS)
&& (buf = read_file(0, &size, SYS_ENTRY_FILE)) != NULL)
{
--
2.27.0

View File

@ -0,0 +1,90 @@
From 1e64387af427ea8b610ea444715822ec7e2c874d Mon Sep 17 00:00:00 2001
From: Jean Delvare <jdelvare@suse.de>
Date: Fri, 26 May 2023 17:41:59 +0200
Subject: [PATCH] dmidecode: Add support for Loongarch
SMBIOS specification version 3.6.0 adds support for the Loongarch
processor architecture.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
dmidecode.c | 28 ++++++++++++++++++++++++++++
dmidecode.h | 1 +
2 files changed, 29 insertions(+)
diff --git a/dmidecode.c b/dmidecode.c
index fbf9f9a..82d264c 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -58,6 +58,8 @@
* https://trustedcomputinggroup.org/pc-client-platform-tpm-profile-ptp-specification/
* - "RedFish Host Interface Specification" (DMTF DSP0270)
* https://www.dmtf.org/sites/default/files/DSP0270_1.0.1.pdf
+ * - LoongArch Reference Manual, volume 1
+ * https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_cpucfg
*/
#include <fcntl.h>
@@ -988,6 +990,24 @@ static const char *dmi_processor_family(const struct dmi_header *h, u16 ver)
{ 0x200, "RV32" },
{ 0x201, "RV64" },
{ 0x202, "RV128" },
+
+ { 0x258, "LoongArch" },
+ { 0x259, "Loongson 1" },
+ { 0x25A, "Loongson 2" },
+ { 0x25B, "Loongson 3" },
+ { 0x25C, "Loongson 2K" },
+ { 0x25D, "Loongson 3A" },
+ { 0x25E, "Loongson 3B" },
+ { 0x25F, "Loongson 3C" },
+ { 0x260, "Loongson 3D" },
+ { 0x261, "Loongson 3E" },
+ { 0x262, "Dual-Core Loongson 2K 2xxx" },
+ { 0x26C, "Quad-Core Loongson 3A 5xxx" },
+ { 0x26D, "Multi-Core Loongson 3A 5xxx" },
+ { 0x26E, "Quad-Core Loongson 3B 5xxx" },
+ { 0x26F, "Multi-Core Loongson 3B 5xxx" },
+ { 0x270, "Multi-Core Loongson 3C 5xxx" },
+ { 0x271, "Multi-Core Loongson 3D 5xxx" },
};
/*
* Note to developers: when adding entries to this list, check if
@@ -1106,6 +1126,9 @@ static enum cpuid_type dmi_get_cpuid_type(const struct dmi_header *h)
|| (type >= 0xB6 && type <= 0xB7) /* AMD */
|| (type >= 0xE4 && type <= 0xEF)) /* AMD */
return cpuid_x86_amd;
+ else if ((type >= 0x258 && type <= 0x262) /* Loongarch */
+ || (type >= 0x26C && type <= 0x271)) /* Loongarch */
+ return cpuid_loongarch;
/* neither X86 nor ARM */
return cpuid_none;
@@ -1203,6 +1226,11 @@ void dmi_print_cpuid(void (*print_cb)(const char *name, const char *format, ...)
((eax >> 4) & 0xF) | (((eax >> 8) & 0xF) == 0xF ? (eax >> 12) & 0xF0 : 0),
eax & 0xF);
break;
+
+ case cpuid_loongarch: /* LoongArch Reference Manual, volume 1 */
+ eax = DWORD(p);
+ print_cb(label, "Processor Identity 0x%08x\n", eax);
+ break;
default:
return;
}
diff --git a/dmidecode.h b/dmidecode.h
index 318cdc6..04c9c93 100644
--- a/dmidecode.h
+++ b/dmidecode.h
@@ -40,6 +40,7 @@ enum cpuid_type
cpuid_arm_soc_id,
cpuid_x86_intel,
cpuid_x86_amd,
+ cpuid_loongarch,
};
extern enum cpuid_type cpuid_type;
--
2.27.0

View File

@ -11,10 +11,10 @@ Signed-off-by: guoxiaoqi <guoxiaoqi2@huawei.com>
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/dmidecode.c b/dmidecode.c
index a3e9d6c..35c19c2 100644
index 54f59c1..fbf9f9a 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -447,7 +447,7 @@ static void dmi_system_uuid(const u8 *p, u16 ver)
@@ -482,7 +482,7 @@ static void dmi_system_uuid(void (*print_cb)(const char *name, const char *forma
* network byte order, so I am reluctant to apply the byte-swapping
* for older versions.
*/
@ -24,10 +24,10 @@ index a3e9d6c..35c19c2 100644
if (print_cb)
print_cb(attr,
diff --git a/dmiopt.c b/dmiopt.c
index 2f285f3..dede0f9 100644
index fa84f22..d2f37c5 100644
--- a/dmiopt.c
+++ b/dmiopt.c
@@ -276,6 +276,7 @@ int parse_command_line(int argc, char * const argv[])
@@ -280,6 +280,7 @@ int parse_command_line(int argc, char * const argv[])
{ "oem-string", required_argument, NULL, 'O' },
{ "no-sysfs", no_argument, NULL, 'S' },
{ "version", no_argument, NULL, 'V' },
@ -35,7 +35,7 @@ index 2f285f3..dede0f9 100644
{ NULL, 0, NULL, 0 }
};
@@ -328,6 +329,9 @@ int parse_command_line(int argc, char * const argv[])
@@ -335,6 +336,9 @@ int parse_command_line(int argc, char * const argv[])
case 'V':
opt.flags |= FLAG_VERSION;
break;
@ -45,7 +45,7 @@ index 2f285f3..dede0f9 100644
case '?':
switch (optopt)
{
@@ -375,6 +379,7 @@ void print_help(void)
@@ -383,6 +387,7 @@ void print_help(void)
" --dump-bin FILE Dump the DMI data to a binary file\n"
" --from-dump FILE Read the DMI data from a binary file\n"
" --no-sysfs Do not attempt to read DMI data from sysfs files\n"
@ -54,17 +54,17 @@ index 2f285f3..dede0f9 100644
" -V, --version Display the version and exit\n";
diff --git a/dmiopt.h b/dmiopt.h
index 2374637..4ada9ac 100644
index 62ffcbb..4d25f9f 100644
--- a/dmiopt.h
+++ b/dmiopt.h
@@ -46,6 +46,7 @@ extern struct opt opt;
#define FLAG_DUMP_BIN (1 << 4)
@@ -47,6 +47,7 @@ extern struct opt opt;
#define FLAG_FROM_DUMP (1 << 5)
#define FLAG_NO_SYSFS (1 << 6)
#define FLAG_NO_QUIRKS (1 << 7)
+#define FLAG_COMPAT_UUID (1 << 10)
int parse_command_line(int argc, char * const argv[]);
void print_help(void);
--
1.8.3.1
2.33.0

Binary file not shown.

BIN
dmidecode-3.5.tar.xz Normal file

Binary file not shown.

View File

@ -1,75 +0,0 @@
From 6ca381c1247c81f74e1ca4e7706f70bdda72e6f2 Mon Sep 17 00:00:00 2001
From: Jean Delvare <jdelvare@suse.de>
Date: Mon, 20 Feb 2023 14:53:31 +0100
Subject: [PATCH] dmidecode: Do not let --dump-bin overwrite an existing file
Make sure that the file passed to option --dump-bin does not already
exist. In practice, it is rather unlikely that an honest user would
want to overwrite an existing dump file, while this possibility
could be used by a rogue user to corrupt a system file.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Jerry Hoemann <jerry.hoemann@hpe.com>
---
dmidecode.c | 14 ++++++++++++--
man/dmidecode.8 | 3 ++-
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/dmidecode.c b/dmidecode.c
index 6e7be63..82efa2d 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -60,6 +60,7 @@
* https://www.dmtf.org/sites/default/files/DSP0270_1.0.1.pdf
*/
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
@@ -5412,13 +5413,22 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
static int dmi_table_dump(const u8 *ep, u32 ep_len, const u8 *table,
u32 table_len)
{
+ int fd;
FILE *f;
- f = fopen(opt.dumpfile, "wb");
+ fd = open(opt.dumpfile, O_WRONLY|O_CREAT|O_EXCL, 0666);
+ if (fd == -1)
+ {
+ fprintf(stderr, "%s: ", opt.dumpfile);
+ perror("open");
+ return -1;
+ }
+
+ f = fdopen(fd, "wb");
if (!f)
{
fprintf(stderr, "%s: ", opt.dumpfile);
- perror("fopen");
+ perror("fdopen");
return -1;
}
diff --git a/man/dmidecode.8 b/man/dmidecode.8
index 62aa304..83affc2 100644
--- a/man/dmidecode.8
+++ b/man/dmidecode.8
@@ -1,4 +1,4 @@
-.TH DMIDECODE 8 "January 2019" "dmidecode"
+.TH DMIDECODE 8 "February 2023" "dmidecode"
.\"
.SH NAME
dmidecode \- \s-1DMI\s0 table decoder
@@ -164,6 +164,7 @@ hexadecimal and \s-1ASCII\s0. This option is mainly useful for debugging.
Do not decode the entries, instead dump the DMI data to a file in binary
form. The generated file is suitable to pass to \fB--from-dump\fP
later.
+\fIFILE\fP must not exist.
.TP
.BR " " " " "--from-dump \fIFILE\fP"
Read the DMI data from a binary file previously generated using
--
2.28.1

View File

@ -1,231 +0,0 @@
From 39b2dd7b6ab719b920e96ed832cfb4bdd664e808 Mon Sep 17 00:00:00 2001
From: Jean Delvare <jdelvare@suse.de>
Date: Mon, 20 Feb 2023 14:53:21 +0100
Subject: [PATCH] dmidecode: Split table fetching from decoding
Clean up function dmi_table so that it does only one thing:
* dmi_table() is renamed to dmi_table_get(). It now retrieves the
DMI table, but does not process it any longer.
* Decoding or dumping the table is now done in smbios3_decode(),
smbios_decode() and legacy_decode().
No functional change.
A side effect of this change is that writing the header and body of
dump files is now done in a single location. This is required to
further consolidate the writing of dump files.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Jerry Hoemann <jerry.hoemann@hpe.com>
---
dmidecode.c | 86 ++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 62 insertions(+), 24 deletions(-)
diff --git a/dmidecode.c b/dmidecode.c
index e2fc882..0ab04da 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -5567,8 +5567,9 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
}
}
-static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
- u32 flags)
+/* Allocates a buffer for the table, must be freed by the caller */
+static u8 *dmi_table_get(off_t base, u32 *len, u16 num, u32 ver,
+ const char *devmem, u32 flags)
{
u8 *buf;
@@ -5587,7 +5588,7 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
{
if (num)
pr_info("%u structures occupying %u bytes.",
- num, len);
+ num, *len);
if (!(opt.flags & FLAG_FROM_DUMP))
pr_info("Table at 0x%08llX.",
(unsigned long long)base);
@@ -5605,19 +5606,19 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
* would be the result of the kernel truncating the table on
* parse error.
*/
- size_t size = len;
+ size_t size = *len;
buf = read_file(flags & FLAG_NO_FILE_OFFSET ? 0 : base,
&size, devmem);
- if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len)
+ if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)*len)
{
fprintf(stderr, "Wrong DMI structures length: %u bytes "
"announced, only %lu bytes available.\n",
- len, (unsigned long)size);
+ *len, (unsigned long)size);
}
- len = size;
+ *len = size;
}
else
- buf = mem_chunk(base, len, devmem);
+ buf = mem_chunk(base, *len, devmem);
if (buf == NULL)
{
@@ -5627,15 +5628,9 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
fprintf(stderr,
"Try compiling dmidecode with -DUSE_MMAP.\n");
#endif
- return;
}
- if (opt.flags & FLAG_DUMP_BIN)
- dmi_table_dump(buf, len);
- else
- dmi_table_decode(buf, len, num, ver >> 8, flags);
-
- free(buf);
+ return buf;
}
@@ -5670,8 +5665,9 @@ static void overwrite_smbios3_address(u8 *buf)
static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
{
- u32 ver;
+ u32 ver, len;
u64 offset;
+ u8 *table;
/* Don't let checksum run beyond the buffer */
if (buf[0x06] > 0x20)
@@ -5698,8 +5694,12 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
return 0;
}
- dmi_table(((off_t)offset.h << 32) | offset.l,
- DWORD(buf + 0x0C), 0, ver, devmem, flags | FLAG_STOP_AT_EOT);
+ /* Maximum length, may get trimmed */
+ len = DWORD(buf + 0x0C);
+ table = dmi_table_get(((off_t)offset.h << 32) | offset.l, &len, 0, ver,
+ devmem, flags | FLAG_STOP_AT_EOT);
+ if (table == NULL)
+ return 1;
if (opt.flags & FLAG_DUMP_BIN)
{
@@ -5708,11 +5708,19 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
memcpy(crafted, buf, 32);
overwrite_smbios3_address(crafted);
+ dmi_table_dump(table, len);
if (!(opt.flags & FLAG_QUIET))
pr_comment("Writing %d bytes to %s.", crafted[0x06],
opt.dumpfile);
write_dump(0, crafted[0x06], crafted, opt.dumpfile, 1);
}
+ else
+ {
+ dmi_table_decode(table, len, 0, ver >> 8,
+ flags | FLAG_STOP_AT_EOT);
+ }
+
+ free(table);
return 1;
}
@@ -5742,7 +5750,9 @@ static void dmi_fixup_version(u16 *ver)
static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
{
- u16 ver;
+ u16 ver, num;
+ u32 len;
+ u8 *table;
/* Don't let checksum run beyond the buffer */
if (buf[0x05] > 0x20)
@@ -5770,8 +5780,13 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
pr_info("SMBIOS %u.%u present.",
ver >> 8, ver & 0xFF);
- dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C),
- ver << 8, devmem, flags);
+ /* Maximum length, may get trimmed */
+ len = WORD(buf + 0x16);
+ num = WORD(buf + 0x1C);
+ table = dmi_table_get(DWORD(buf + 0x18), &len, num, ver << 8,
+ devmem, flags);
+ if (table == NULL)
+ return 1;
if (opt.flags & FLAG_DUMP_BIN)
{
@@ -5780,27 +5795,43 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
memcpy(crafted, buf, 32);
overwrite_dmi_address(crafted + 0x10);
+ dmi_table_dump(table, len);
if (!(opt.flags & FLAG_QUIET))
pr_comment("Writing %d bytes to %s.", crafted[0x05],
opt.dumpfile);
write_dump(0, crafted[0x05], crafted, opt.dumpfile, 1);
}
+ else
+ {
+ dmi_table_decode(table, len, num, ver, flags);
+ }
+
+ free(table);
return 1;
}
static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
{
+ u16 ver, num;
+ u32 len;
+ u8 *table;
+
if (!checksum(buf, 0x0F))
return 0;
+ ver = ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F);
if (!(opt.flags & FLAG_QUIET))
pr_info("Legacy DMI %u.%u present.",
buf[0x0E] >> 4, buf[0x0E] & 0x0F);
- dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C),
- ((buf[0x0E] & 0xF0) << 12) + ((buf[0x0E] & 0x0F) << 8),
- devmem, flags);
+ /* Maximum length, may get trimmed */
+ len = WORD(buf + 0x06);
+ num = WORD(buf + 0x0C);
+ table = dmi_table_get(DWORD(buf + 0x08), &len, num, ver << 8,
+ devmem, flags);
+ if (table == NULL)
+ return 1;
if (opt.flags & FLAG_DUMP_BIN)
{
@@ -5809,11 +5840,18 @@ static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
memcpy(crafted, buf, 16);
overwrite_dmi_address(crafted);
+ dmi_table_dump(table, len);
if (!(opt.flags & FLAG_QUIET))
pr_comment("Writing %d bytes to %s.", 0x0F,
opt.dumpfile);
write_dump(0, 0x0F, crafted, opt.dumpfile, 1);
}
+ else
+ {
+ dmi_table_decode(table, len, num, ver, flags);
+ }
+
+ free(table);
return 1;
}
--
2.28.0.windows.1

View File

@ -1,191 +0,0 @@
From d8cfbc808f387e87091c25e7d5b8c2bb348bb206 Mon Sep 17 00:00:00 2001
From: Jean Delvare <jdelvare@suse.de>
Date: Mon, 20 Feb 2023 14:53:25 +0100
Subject: [PATCH] dmidecode: Write the whole dump file at once
When option --dump-bin is used, write the whole dump file at once,
instead of opening and closing the file separately for the table
and then for the entry point.
As the file writing function is no longer generic, it gets moved
from util.c to dmidecode.c.
One minor functional change resulting from the new implementation is
that the entry point is written first now, so the messages printed
are swapped.
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Jerry Hoemann <jerry.hoemann@hpe.com>
---
dmidecode.c | 69 +++++++++++++++++++++++++++++++++++++++--------------
util.c | 40 -------------------------------
util.h | 1 -
3 files changed, 51 insertions(+), 59 deletions(-)
diff --git a/dmidecode.c b/dmidecode.c
index 0ab04da..6e7be63 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -5409,11 +5409,56 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
}
}
-static void dmi_table_dump(const u8 *buf, u32 len)
+static int dmi_table_dump(const u8 *ep, u32 ep_len, const u8 *table,
+ u32 table_len)
{
+ FILE *f;
+
+ f = fopen(opt.dumpfile, "wb");
+ if (!f)
+ {
+ fprintf(stderr, "%s: ", opt.dumpfile);
+ perror("fopen");
+ return -1;
+ }
+
+ if (!(opt.flags & FLAG_QUIET))
+ pr_comment("Writing %d bytes to %s.", ep_len, opt.dumpfile);
+ if (fwrite(ep, ep_len, 1, f) != 1)
+ {
+ fprintf(stderr, "%s: ", opt.dumpfile);
+ perror("fwrite");
+ goto err_close;
+ }
+
+ if (fseek(f, 32, SEEK_SET) != 0)
+ {
+ fprintf(stderr, "%s: ", opt.dumpfile);
+ perror("fseek");
+ goto err_close;
+ }
+
if (!(opt.flags & FLAG_QUIET))
- pr_comment("Writing %d bytes to %s.", len, opt.dumpfile);
- write_dump(32, len, buf, opt.dumpfile, 0);
+ pr_comment("Writing %d bytes to %s.", table_len, opt.dumpfile);
+ if (fwrite(table, table_len, 1, f) != 1)
+ {
+ fprintf(stderr, "%s: ", opt.dumpfile);
+ perror("fwrite");
+ goto err_close;
+ }
+
+ if (fclose(f))
+ {
+ fprintf(stderr, "%s: ", opt.dumpfile);
+ perror("fclose");
+ return -1;
+ }
+
+ return 0;
+
+err_close:
+ fclose(f);
+ return -1;
}
static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
@@ -5708,11 +5753,7 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
memcpy(crafted, buf, 32);
overwrite_smbios3_address(crafted);
- dmi_table_dump(table, len);
- if (!(opt.flags & FLAG_QUIET))
- pr_comment("Writing %d bytes to %s.", crafted[0x06],
- opt.dumpfile);
- write_dump(0, crafted[0x06], crafted, opt.dumpfile, 1);
+ dmi_table_dump(crafted, crafted[0x06], table, len);
}
else
{
@@ -5795,11 +5836,7 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
memcpy(crafted, buf, 32);
overwrite_dmi_address(crafted + 0x10);
- dmi_table_dump(table, len);
- if (!(opt.flags & FLAG_QUIET))
- pr_comment("Writing %d bytes to %s.", crafted[0x05],
- opt.dumpfile);
- write_dump(0, crafted[0x05], crafted, opt.dumpfile, 1);
+ dmi_table_dump(crafted, crafted[0x05], table, len);
}
else
{
@@ -5840,11 +5877,7 @@ static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
memcpy(crafted, buf, 16);
overwrite_dmi_address(crafted);
- dmi_table_dump(table, len);
- if (!(opt.flags & FLAG_QUIET))
- pr_comment("Writing %d bytes to %s.", 0x0F,
- opt.dumpfile);
- write_dump(0, 0x0F, crafted, opt.dumpfile, 1);
+ dmi_table_dump(crafted, 0x0F, table, len);
}
else
{
diff --git a/util.c b/util.c
index 04aaadd..1547096 100644
--- a/util.c
+++ b/util.c
@@ -259,46 +259,6 @@ void *mem_chunk(off_t base, size_t len, const char *devmem)
return p;
}
-int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add)
-{
- FILE *f;
-
- f = fopen(dumpfile, add ? "r+b" : "wb");
- if (!f)
- {
- fprintf(stderr, "%s: ", dumpfile);
- perror("fopen");
- return -1;
- }
-
- if (fseek(f, base, SEEK_SET) != 0)
- {
- fprintf(stderr, "%s: ", dumpfile);
- perror("fseek");
- goto err_close;
- }
-
- if (fwrite(data, len, 1, f) != 1)
- {
- fprintf(stderr, "%s: ", dumpfile);
- perror("fwrite");
- goto err_close;
- }
-
- if (fclose(f))
- {
- fprintf(stderr, "%s: ", dumpfile);
- perror("fclose");
- return -1;
- }
-
- return 0;
-
-err_close:
- fclose(f);
- return -1;
-}
-
/* Returns end - start + 1, assuming start < end */
u64 u64_range(u64 start, u64 end)
{
diff --git a/util.h b/util.h
index 3094cf8..ef24eb9 100644
--- a/util.h
+++ b/util.h
@@ -27,5 +27,4 @@
int checksum(const u8 *buf, size_t len);
void *read_file(off_t base, size_t *len, const char *filename);
void *mem_chunk(off_t base, size_t len, const char *devmem);
-int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add);
u64 u64_range(u64 start, u64 end);
--
2.28.1

View File

@ -1,6 +1,6 @@
Name: dmidecode
Version: 3.4
Release: 4
Version: 3.5
Release: 3
Epoch: 1
Summary: DMI data report tool
@ -9,13 +9,12 @@ URL: https://www.nongnu.org/dmidecode/
Source0: http://download.savannah.gnu.org/releases/dmidecode/%{name}-%{version}.tar.xz
Patch6000: bugfix-compat_uuid.patch
Patch6001: dmidecode-Split-table-fetching-from-decoding.patch
Patch6002: dmidecode-Write-the-whole-dump-file-at-once.patch
Patch6003: dmidecode-Do-not-let-dump-bin-overwrite-an-existing-.patch
Patch6001: Consistently-use-read_file-when-reading-from-a-dump-file.patch
Patch6002: backport-Support-Loongarch.patch
BuildRequires: make gcc xz
ExclusiveArch: %{ix86} x86_64 ia64 aarch64 amd64 sw_64 loongarch64 riscv64
ExclusiveArch: %{ix86} x86_64 ia64 aarch64 amd64 sw_64 loongarch64 riscv64 ppc64le
%description
Dmidecode reports information about your system's hardware as described
@ -53,6 +52,24 @@ make %{?_smp_mflags} CFLAGS="%{__global_cflags}" LDFLAGS="%{__global_ldflags}"
%{_mandir}/man8/*.8.gz
%changelog
* Fri Sep 20 2024 liyunqing <liyunqing@kylinos.cn> - 1:3.5-3
- Type:backport
- ID:NA
- SUG:NA
- DESC: Add support for Loongarch processor architecture
* Thu Sep 12 2024 liyunqing <liyunqing@kylinos.cn> - 1:3.5-2
- backport: Use read_file instead of mem_chunk
* Mon Feb 5 2024 nicunshu <nicunshu@huawei.com> - 1:3.5-1
- Upgrade to 3.5
* Thu Dec 14 2023 lvgenggeng <lvgenggeng@uniontech.com> - 1:3.4-6
- backport: Fix segmentation fault in dmi_hp_240_attr()
* Thu Dec 14 2023 jiahua.yu <jiahua.yu@shingroup.cn> - 1:3.4-5
- init support for arch ppc64le
* Fri Aug 04 2023 Jingwiw <wangjingwei@iscas.ac.cn> - 1:3.4-4
- enable riscv64 architecture