Commit a185a099 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-kunit-6.1-rc1-2' of...

Merge tag 'linux-kselftest-kunit-6.1-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull more KUnit updates from Shuah Khan:
 "Features and fixes:

   - simplify resource use

   - make kunit_malloc() and kunit_free() allocations and frees
     consistent. kunit_free() frees only the memory allocated by
     kunit_malloc()

   - stop downloading risc-v opensbi binaries using wget

   - other fixes and improvements to tool and KUnit framework"

* tag 'linux-kselftest-kunit-6.1-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  Documentation: kunit: Update description of --alltests option
  kunit: declare kunit_assert structs as const
  kunit: rename base KUNIT_ASSERTION macro to _KUNIT_FAILED
  kunit: remove format func from struct kunit_assert, get it to 0 bytes
  kunit: tool: Don't download risc-v opensbi firmware with wget
  kunit: make kunit_kfree(NULL) a no-op to match kfree()
  kunit: make kunit_kfree() not segfault on invalid inputs
  kunit: make kunit_kfree() only work on pointers from kunit_malloc() and friends
  kunit: drop test pointer in string_stream_fragment
  kunit: string-stream: Simplify resource use
parents 661e0096 e98c4f6a
...@@ -251,14 +251,15 @@ command line arguments: ...@@ -251,14 +251,15 @@ command line arguments:
compiling a kernel (using ``build`` or ``run`` commands). For example: compiling a kernel (using ``build`` or ``run`` commands). For example:
to enable compiler warnings, we can pass ``--make_options W=1``. to enable compiler warnings, we can pass ``--make_options W=1``.
- ``--alltests``: Builds a UML kernel with all config options enabled - ``--alltests``: Enable a predefined set of options in order to build
using ``make allyesconfig``. This allows us to run as many tests as as many tests as possible.
possible.
.. note:: The list of enabled options can be found in
.. note:: It is slow and prone to breakage as new options are ``tools/testing/kunit/configs/all_tests.config``.
added or modified. Instead, enable all tests
which have satisfied dependencies by adding If you only want to enable all tests with otherwise satisfied
``CONFIG_KUNIT_ALL_TESTS=y`` to your ``.kunitconfig``. dependencies, instead add ``CONFIG_KUNIT_ALL_TESTS=y`` to your
``.kunitconfig``.
- ``--kunitconfig``: Specifies the path or the directory of the ``.kunitconfig`` - ``--kunitconfig``: Specifies the path or the directory of the ``.kunitconfig``
file. For example: file. For example:
......
...@@ -42,16 +42,15 @@ struct kunit_loc { ...@@ -42,16 +42,15 @@ struct kunit_loc {
/** /**
* struct kunit_assert - Data for printing a failed assertion or expectation. * struct kunit_assert - Data for printing a failed assertion or expectation.
* @format: a function which formats the data in this kunit_assert to a string.
* *
* Represents a failed expectation/assertion. Contains all the data necessary to * Represents a failed expectation/assertion. Contains all the data necessary to
* format a string to a user reporting the failure. * format a string to a user reporting the failure.
*/ */
struct kunit_assert { struct kunit_assert {};
void (*format)(const struct kunit_assert *assert,
const struct va_format *message, typedef void (*assert_format_t)(const struct kunit_assert *assert,
struct string_stream *stream); const struct va_format *message,
}; struct string_stream *stream);
void kunit_assert_prologue(const struct kunit_loc *loc, void kunit_assert_prologue(const struct kunit_loc *loc,
enum kunit_assert_type type, enum kunit_assert_type type,
...@@ -71,16 +70,6 @@ void kunit_fail_assert_format(const struct kunit_assert *assert, ...@@ -71,16 +70,6 @@ void kunit_fail_assert_format(const struct kunit_assert *assert,
const struct va_format *message, const struct va_format *message,
struct string_stream *stream); struct string_stream *stream);
/**
* KUNIT_INIT_FAIL_ASSERT_STRUCT - Initializer for &struct kunit_fail_assert.
*
* Initializes a &struct kunit_fail_assert. Intended to be used in
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/
#define KUNIT_INIT_FAIL_ASSERT_STRUCT { \
.assert = { .format = kunit_fail_assert_format }, \
}
/** /**
* struct kunit_unary_assert - Represents a KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE} * struct kunit_unary_assert - Represents a KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE}
* @assert: The parent of this type. * @assert: The parent of this type.
...@@ -110,7 +99,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert, ...@@ -110,7 +99,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_UNARY_ASSERT_STRUCT(cond, expect_true) { \ #define KUNIT_INIT_UNARY_ASSERT_STRUCT(cond, expect_true) { \
.assert = { .format = kunit_unary_assert_format }, \
.condition = cond, \ .condition = cond, \
.expected_true = expect_true \ .expected_true = expect_true \
} }
...@@ -145,7 +133,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, ...@@ -145,7 +133,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(txt, val) { \ #define KUNIT_INIT_PTR_NOT_ERR_STRUCT(txt, val) { \
.assert = { .format = kunit_ptr_not_err_assert_format }, \
.text = txt, \ .text = txt, \
.value = val \ .value = val \
} }
...@@ -190,7 +177,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, ...@@ -190,7 +177,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
* KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a binary assert like * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a binary assert like
* kunit_binary_assert, kunit_binary_ptr_assert, etc. * kunit_binary_assert, kunit_binary_ptr_assert, etc.
* *
* @format_func: a function which formats the assert to a string.
* @text_: Pointer to a kunit_binary_assert_text. * @text_: Pointer to a kunit_binary_assert_text.
* @left_val: The actual evaluated value of the expression in the left slot. * @left_val: The actual evaluated value of the expression in the left slot.
* @right_val: The actual evaluated value of the expression in the right slot. * @right_val: The actual evaluated value of the expression in the right slot.
...@@ -200,11 +186,9 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, ...@@ -200,11 +186,9 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
* fields but with different types for left_val/right_val. * fields but with different types for left_val/right_val.
* This is ultimately used by binary assertion macros like KUNIT_EXPECT_EQ, etc. * This is ultimately used by binary assertion macros like KUNIT_EXPECT_EQ, etc.
*/ */
#define KUNIT_INIT_BINARY_ASSERT_STRUCT(format_func, \ #define KUNIT_INIT_BINARY_ASSERT_STRUCT(text_, \
text_, \
left_val, \ left_val, \
right_val) { \ right_val) { \
.assert = { .format = format_func }, \
.text = text_, \ .text = text_, \
.left_value = left_val, \ .left_value = left_val, \
.right_value = right_val \ .right_value = right_val \
......
...@@ -300,22 +300,6 @@ typedef bool (*kunit_resource_match_t)(struct kunit *test, ...@@ -300,22 +300,6 @@ typedef bool (*kunit_resource_match_t)(struct kunit *test,
struct kunit_resource *res, struct kunit_resource *res,
void *match_data); void *match_data);
/**
* kunit_resource_instance_match() - Match a resource with the same instance.
* @test: Test case to which the resource belongs.
* @res: The resource.
* @match_data: The resource pointer to match against.
*
* An instance of kunit_resource_match_t that matches a resource whose
* allocation matches @match_data.
*/
static inline bool kunit_resource_instance_match(struct kunit *test,
struct kunit_resource *res,
void *match_data)
{
return res->data == match_data;
}
/** /**
* kunit_resource_name_match() - Match a resource with the same name. * kunit_resource_name_match() - Match a resource with the same name.
* @test: Test case to which the resource belongs. * @test: Test case to which the resource belongs.
......
...@@ -473,30 +473,30 @@ void kunit_do_failed_assertion(struct kunit *test, ...@@ -473,30 +473,30 @@ void kunit_do_failed_assertion(struct kunit *test,
const struct kunit_loc *loc, const struct kunit_loc *loc,
enum kunit_assert_type type, enum kunit_assert_type type,
const struct kunit_assert *assert, const struct kunit_assert *assert,
assert_format_t assert_format,
const char *fmt, ...); const char *fmt, ...);
#define KUNIT_ASSERTION(test, assert_type, pass, assert_class, INITIALIZER, fmt, ...) do { \ #define _KUNIT_FAILED(test, assert_type, assert_class, assert_format, INITIALIZER, fmt, ...) do { \
if (unlikely(!(pass))) { \ static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \
static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ const struct assert_class __assertion = INITIALIZER; \
struct assert_class __assertion = INITIALIZER; \ kunit_do_failed_assertion(test, \
kunit_do_failed_assertion(test, \ &__loc, \
&__loc, \ assert_type, \
assert_type, \ &__assertion.assert, \
&__assertion.assert, \ assert_format, \
fmt, \ fmt, \
##__VA_ARGS__); \ ##__VA_ARGS__); \
} \
} while (0) } while (0)
#define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \ #define KUNIT_FAIL_ASSERTION(test, assert_type, fmt, ...) \
KUNIT_ASSERTION(test, \ _KUNIT_FAILED(test, \
assert_type, \ assert_type, \
false, \ kunit_fail_assert, \
kunit_fail_assert, \ kunit_fail_assert_format, \
KUNIT_INIT_FAIL_ASSERT_STRUCT, \ {}, \
fmt, \ fmt, \
##__VA_ARGS__) ##__VA_ARGS__)
/** /**
* KUNIT_FAIL() - Always causes a test to fail when evaluated. * KUNIT_FAIL() - Always causes a test to fail when evaluated.
...@@ -521,14 +521,19 @@ void kunit_do_failed_assertion(struct kunit *test, ...@@ -521,14 +521,19 @@ void kunit_do_failed_assertion(struct kunit *test,
expected_true, \ expected_true, \
fmt, \ fmt, \
...) \ ...) \
KUNIT_ASSERTION(test, \ do { \
assert_type, \ if (likely(!!(condition) == !!expected_true)) \
!!(condition) == !!expected_true, \ break; \
kunit_unary_assert, \ \
KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ _KUNIT_FAILED(test, \
expected_true), \ assert_type, \
fmt, \ kunit_unary_assert, \
##__VA_ARGS__) kunit_unary_assert_format, \
KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \
expected_true), \
fmt, \
##__VA_ARGS__); \
} while (0)
#define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \
KUNIT_UNARY_ASSERTION(test, \ KUNIT_UNARY_ASSERTION(test, \
...@@ -578,16 +583,18 @@ do { \ ...@@ -578,16 +583,18 @@ do { \
.right_text = #right, \ .right_text = #right, \
}; \ }; \
\ \
KUNIT_ASSERTION(test, \ if (likely(__left op __right)) \
assert_type, \ break; \
__left op __right, \ \
assert_class, \ _KUNIT_FAILED(test, \
KUNIT_INIT_BINARY_ASSERT_STRUCT(format_func, \ assert_type, \
&__text, \ assert_class, \
__left, \ format_func, \
__right), \ KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \
fmt, \ __left, \
##__VA_ARGS__); \ __right), \
fmt, \
##__VA_ARGS__); \
} while (0) } while (0)
#define KUNIT_BINARY_INT_ASSERTION(test, \ #define KUNIT_BINARY_INT_ASSERTION(test, \
...@@ -636,16 +643,19 @@ do { \ ...@@ -636,16 +643,19 @@ do { \
.right_text = #right, \ .right_text = #right, \
}; \ }; \
\ \
KUNIT_ASSERTION(test, \ if (likely(strcmp(__left, __right) op 0)) \
assert_type, \ break; \
strcmp(__left, __right) op 0, \ \
kunit_binary_str_assert, \ \
KUNIT_INIT_BINARY_ASSERT_STRUCT(kunit_binary_str_assert_format,\ _KUNIT_FAILED(test, \
&__text, \ assert_type, \
__left, \ kunit_binary_str_assert, \
__right), \ kunit_binary_str_assert_format, \
fmt, \ KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \
##__VA_ARGS__); \ __left, \
__right), \
fmt, \
##__VA_ARGS__); \
} while (0) } while (0)
#define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
...@@ -656,14 +666,16 @@ do { \ ...@@ -656,14 +666,16 @@ do { \
do { \ do { \
const typeof(ptr) __ptr = (ptr); \ const typeof(ptr) __ptr = (ptr); \
\ \
KUNIT_ASSERTION(test, \ if (!IS_ERR_OR_NULL(__ptr)) \
assert_type, \ break; \
!IS_ERR_OR_NULL(__ptr), \ \
kunit_ptr_not_err_assert, \ _KUNIT_FAILED(test, \
KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, \ assert_type, \
__ptr), \ kunit_ptr_not_err_assert, \
fmt, \ kunit_ptr_not_err_assert_format, \
##__VA_ARGS__); \ KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, __ptr), \
fmt, \
##__VA_ARGS__); \
} while (0) } while (0)
/** /**
......
...@@ -161,6 +161,13 @@ static void kunit_resource_test_alloc_resource(struct kunit *test) ...@@ -161,6 +161,13 @@ static void kunit_resource_test_alloc_resource(struct kunit *test)
kunit_put_resource(res); kunit_put_resource(res);
} }
static inline bool kunit_resource_instance_match(struct kunit *test,
struct kunit_resource *res,
void *match_data)
{
return res->data == match_data;
}
/* /*
* Note: tests below use kunit_alloc_and_get_resource(), so as a consequence * Note: tests below use kunit_alloc_and_get_resource(), so as a consequence
* they have a reference to the associated resource that they must release * they have a reference to the associated resource that they must release
......
...@@ -12,62 +12,29 @@ ...@@ -12,62 +12,29 @@
#include "string-stream.h" #include "string-stream.h"
struct string_stream_fragment_alloc_context {
struct kunit *test;
int len;
gfp_t gfp;
};
static int string_stream_fragment_init(struct kunit_resource *res, static struct string_stream_fragment *alloc_string_stream_fragment(
void *context) struct kunit *test, int len, gfp_t gfp)
{ {
struct string_stream_fragment_alloc_context *ctx = context;
struct string_stream_fragment *frag; struct string_stream_fragment *frag;
frag = kunit_kzalloc(ctx->test, sizeof(*frag), ctx->gfp); frag = kunit_kzalloc(test, sizeof(*frag), gfp);
if (!frag) if (!frag)
return -ENOMEM; return ERR_PTR(-ENOMEM);
frag->test = ctx->test; frag->fragment = kunit_kmalloc(test, len, gfp);
frag->fragment = kunit_kmalloc(ctx->test, ctx->len, ctx->gfp);
if (!frag->fragment) if (!frag->fragment)
return -ENOMEM; return ERR_PTR(-ENOMEM);
res->data = frag; return frag;
return 0;
} }
static void string_stream_fragment_free(struct kunit_resource *res) static void string_stream_fragment_destroy(struct kunit *test,
struct string_stream_fragment *frag)
{ {
struct string_stream_fragment *frag = res->data;
list_del(&frag->node); list_del(&frag->node);
kunit_kfree(frag->test, frag->fragment); kunit_kfree(test, frag->fragment);
kunit_kfree(frag->test, frag); kunit_kfree(test, frag);
}
static struct string_stream_fragment *alloc_string_stream_fragment(
struct kunit *test, int len, gfp_t gfp)
{
struct string_stream_fragment_alloc_context context = {
.test = test,
.len = len,
.gfp = gfp
};
return kunit_alloc_resource(test,
string_stream_fragment_init,
string_stream_fragment_free,
gfp,
&context);
}
static int string_stream_fragment_destroy(struct string_stream_fragment *frag)
{
return kunit_destroy_resource(frag->test,
kunit_resource_instance_match,
frag);
} }
int string_stream_vadd(struct string_stream *stream, int string_stream_vadd(struct string_stream *stream,
...@@ -122,7 +89,7 @@ static void string_stream_clear(struct string_stream *stream) ...@@ -122,7 +89,7 @@ static void string_stream_clear(struct string_stream *stream)
frag_container_safe, frag_container_safe,
&stream->fragments, &stream->fragments,
node) { node) {
string_stream_fragment_destroy(frag_container); string_stream_fragment_destroy(stream->test, frag_container);
} }
stream->length = 0; stream->length = 0;
spin_unlock(&stream->lock); spin_unlock(&stream->lock);
...@@ -169,48 +136,23 @@ struct string_stream_alloc_context { ...@@ -169,48 +136,23 @@ struct string_stream_alloc_context {
gfp_t gfp; gfp_t gfp;
}; };
static int string_stream_init(struct kunit_resource *res, void *context) struct string_stream *alloc_string_stream(struct kunit *test, gfp_t gfp)
{ {
struct string_stream *stream; struct string_stream *stream;
struct string_stream_alloc_context *ctx = context;
stream = kunit_kzalloc(ctx->test, sizeof(*stream), ctx->gfp); stream = kunit_kzalloc(test, sizeof(*stream), gfp);
if (!stream) if (!stream)
return -ENOMEM; return ERR_PTR(-ENOMEM);
res->data = stream; stream->gfp = gfp;
stream->gfp = ctx->gfp; stream->test = test;
stream->test = ctx->test;
INIT_LIST_HEAD(&stream->fragments); INIT_LIST_HEAD(&stream->fragments);
spin_lock_init(&stream->lock); spin_lock_init(&stream->lock);
return 0; return stream;
} }
static void string_stream_free(struct kunit_resource *res) void string_stream_destroy(struct string_stream *stream)
{ {
struct string_stream *stream = res->data;
string_stream_clear(stream); string_stream_clear(stream);
} }
struct string_stream *alloc_string_stream(struct kunit *test, gfp_t gfp)
{
struct string_stream_alloc_context context = {
.test = test,
.gfp = gfp
};
return kunit_alloc_resource(test,
string_stream_init,
string_stream_free,
gfp,
&context);
}
int string_stream_destroy(struct string_stream *stream)
{
return kunit_destroy_resource(stream->test,
kunit_resource_instance_match,
stream);
}
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include <linux/stdarg.h> #include <linux/stdarg.h>
struct string_stream_fragment { struct string_stream_fragment {
struct kunit *test;
struct list_head node; struct list_head node;
char *fragment; char *fragment;
}; };
...@@ -46,6 +45,6 @@ int string_stream_append(struct string_stream *stream, ...@@ -46,6 +45,6 @@ int string_stream_append(struct string_stream *stream,
bool string_stream_is_empty(struct string_stream *stream); bool string_stream_is_empty(struct string_stream *stream);
int string_stream_destroy(struct string_stream *stream); void string_stream_destroy(struct string_stream *stream);
#endif /* _KUNIT_STRING_STREAM_H */ #endif /* _KUNIT_STRING_STREAM_H */
...@@ -258,7 +258,7 @@ static void kunit_print_string_stream(struct kunit *test, ...@@ -258,7 +258,7 @@ static void kunit_print_string_stream(struct kunit *test,
static void kunit_fail(struct kunit *test, const struct kunit_loc *loc, static void kunit_fail(struct kunit *test, const struct kunit_loc *loc,
enum kunit_assert_type type, const struct kunit_assert *assert, enum kunit_assert_type type, const struct kunit_assert *assert,
const struct va_format *message) assert_format_t assert_format, const struct va_format *message)
{ {
struct string_stream *stream; struct string_stream *stream;
...@@ -274,11 +274,11 @@ static void kunit_fail(struct kunit *test, const struct kunit_loc *loc, ...@@ -274,11 +274,11 @@ static void kunit_fail(struct kunit *test, const struct kunit_loc *loc,
} }
kunit_assert_prologue(loc, type, stream); kunit_assert_prologue(loc, type, stream);
assert->format(assert, message, stream); assert_format(assert, message, stream);
kunit_print_string_stream(test, stream); kunit_print_string_stream(test, stream);
WARN_ON(string_stream_destroy(stream)); string_stream_destroy(stream);
} }
static void __noreturn kunit_abort(struct kunit *test) static void __noreturn kunit_abort(struct kunit *test)
...@@ -298,6 +298,7 @@ void kunit_do_failed_assertion(struct kunit *test, ...@@ -298,6 +298,7 @@ void kunit_do_failed_assertion(struct kunit *test,
const struct kunit_loc *loc, const struct kunit_loc *loc,
enum kunit_assert_type type, enum kunit_assert_type type,
const struct kunit_assert *assert, const struct kunit_assert *assert,
assert_format_t assert_format,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list args; va_list args;
...@@ -307,7 +308,7 @@ void kunit_do_failed_assertion(struct kunit *test, ...@@ -307,7 +308,7 @@ void kunit_do_failed_assertion(struct kunit *test,
message.fmt = fmt; message.fmt = fmt;
message.va = &args; message.va = &args;
kunit_fail(test, loc, type, assert, &message); kunit_fail(test, loc, type, assert, assert_format, &message);
va_end(args); va_end(args);
...@@ -713,21 +714,20 @@ void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp) ...@@ -713,21 +714,20 @@ void *kunit_kmalloc_array(struct kunit *test, size_t n, size_t size, gfp_t gfp)
} }
EXPORT_SYMBOL_GPL(kunit_kmalloc_array); EXPORT_SYMBOL_GPL(kunit_kmalloc_array);
void kunit_kfree(struct kunit *test, const void *ptr) static inline bool kunit_kfree_match(struct kunit *test,
struct kunit_resource *res, void *match_data)
{ {
struct kunit_resource *res; /* Only match resources allocated with kunit_kmalloc() and friends. */
return res->free == kunit_kmalloc_array_free && res->data == match_data;
res = kunit_find_resource(test, kunit_resource_instance_match, }
(void *)ptr);
/*
* Removing the resource from the list of resources drops the
* reference count to 1; the final put will trigger the free.
*/
kunit_remove_resource(test, res);
kunit_put_resource(res); void kunit_kfree(struct kunit *test, const void *ptr)
{
if (!ptr)
return;
if (kunit_destroy_resource(test, kunit_kfree_match, (void *)ptr))
KUNIT_FAIL(test, "kunit_kfree: %px already freed or not allocated by kunit", ptr);
} }
EXPORT_SYMBOL_GPL(kunit_kfree); EXPORT_SYMBOL_GPL(kunit_kfree);
......
...@@ -3,17 +3,13 @@ import os ...@@ -3,17 +3,13 @@ import os
import os.path import os.path
import sys import sys
GITHUB_OPENSBI_URL = 'https://github.com/qemu/qemu/raw/master/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin' OPENSBI_FILE = 'opensbi-riscv64-generic-fw_dynamic.bin'
OPENSBI_FILE = os.path.basename(GITHUB_OPENSBI_URL) OPENSBI_PATH = '/usr/share/qemu/' + OPENSBI_FILE
if not os.path.isfile(OPENSBI_FILE): if not os.path.isfile(OPENSBI_PATH):
print('\n\nOpenSBI file is not in the current working directory.\n' print('\n\nOpenSBI bios was not found in "' + OPENSBI_PATH + '".\n'
'Would you like me to download it for you from:\n' + GITHUB_OPENSBI_URL + ' ?\n') 'Please ensure that qemu-system-riscv is installed, or edit the path in "qemu_configs/riscv.py"\n')
response = input('yes/[no]: ') sys.exit()
if response.strip() == 'yes':
os.system('wget ' + GITHUB_OPENSBI_URL)
else:
sys.exit()
QEMU_ARCH = QemuArchParams(linux_arch='riscv', QEMU_ARCH = QemuArchParams(linux_arch='riscv',
kconfig=''' kconfig='''
...@@ -29,4 +25,4 @@ CONFIG_SERIAL_EARLYCON_RISCV_SBI=y''', ...@@ -29,4 +25,4 @@ CONFIG_SERIAL_EARLYCON_RISCV_SBI=y''',
extra_qemu_params=[ extra_qemu_params=[
'-machine', 'virt', '-machine', 'virt',
'-cpu', 'rv64', '-cpu', 'rv64',
'-bios', 'opensbi-riscv64-generic-fw_dynamic.bin']) '-bios', OPENSBI_PATH])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment