Initial Commit

- initial default booting image
This commit is contained in:
2026-11-06 20:45:42 +01:00
commit b8783708ae
15201 changed files with 602532 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
config BR2_PACKAGE_MICROPYTHON
bool "micropython"
depends on BR2_TOOLCHAIN_HAS_THREADS
depends on !BR2_STATIC_LIBS
help
MicroPython is a lean and fast implementation of the Python
3 programming language that is optimised to run on a
microcontroller.
https://micropython.org
if BR2_PACKAGE_MICROPYTHON
config BR2_PACKAGE_MICROPYTHON_LIB
bool "micropython-lib"
help
Core Python libraries ported to MicroPython.
This contains compatible but reduced-functionality versions
of some Python standard library and wider Python ecosystem
modules, as well as some MicroPython-specific libraries
that aren't included in the base package.
if BR2_PACKAGE_MICROPYTHON_LIB
config BR2_PACKAGE_MICROPYTHON_LIB_UNIXFFI
bool "micropython-lib unix-ffi modules"
default y
select BR2_PACKAGE_LIBFFI
select BR2_PACKAGE_PCRE2 # runtime
help
Unix-specific MicroPython packages
These provide additional functionality to MicroPython in
standard environments.
endif # BR2_PACKAGE_MICROPYTHON_LIB
endif # BR2_PACKAGE_MICROPYTHON
comment "micropython needs a toolchain w/ threads, dynamic library"
depends on !BR2_TOOLCHAIN_HAS_THREADS || BR2_STATIC_LIBS

View File

@@ -0,0 +1,85 @@
#!/usr/bin/env python3
"""
Sometime after v1.9.3, micropython-lib's directory structure was cleaned up and
enhanced with manifest files.
Though cleaner, it means it cannot be directly copied into the target.
This script is during build process to perform that conversion.
It makes use of manifestfile.py, which is normally located in micropython's
tool directory.
It also depends on the micropython-lib that is cloned in lib/micropython-lib
during build.
"""
import argparse
import manifestfile
import os
import shutil
def get_library_name_type(manifest_path: str) -> tuple[str, bool]:
split = manifest_path.split("/")
return (split[-2], "unix-ffi" in split) # -1: "manifest.py", -2: library name
def get_all_libraries(mpy_lib_dir: str):
# reuse manifestfile module capabilities to scan the micropython-lib directory
collected_list = manifestfile.ManifestFile(
manifestfile.MODE_FREEZE, {"MPY_LIB_DIR": mpy_lib_dir}
)
collected_list.freeze(mpy_lib_dir)
for file in collected_list.files():
if file.target_path.endswith("manifest.py"):
yield get_library_name_type(file.full_path)
def copy_file(src: str, target: str, destination: str):
s = target.split("/")
s.pop()
d = f"{destination}/{'/'.join(s)}"
os.makedirs(d, exist_ok=True)
shutil.copy(src, f"{destination}/{target}")
def copy_libraries(manifest, destination: str):
for f in manifest.files():
copy_file(f.full_path, f.target_path, destination)
def process_cmdline_args():
parser = argparse.ArgumentParser(
description="Prepare micropython-lib to be installed"
)
parser.add_argument("micropython", help="Path to micropython source directory")
parser.add_argument("destination", help="Destination directory")
parser.add_argument("--ffi", action=argparse.BooleanOptionalAction,
default=True, help="Install libs that require FFI")
args = parser.parse_args()
return args
def main():
args = process_cmdline_args()
mpy_lib_dir = f"{args.micropython}/lib/micropython-lib"
manifest = manifestfile.ManifestFile(
manifestfile.MODE_FREEZE, {"MPY_LIB_DIR": mpy_lib_dir}
)
if args.ffi:
manifest.add_library("unix-ffi", os.path.join("$(MPY_LIB_DIR)", "unix-ffi"),
prepend=True)
for library, is_ffi in get_all_libraries(mpy_lib_dir):
if args.ffi or not is_ffi:
manifest.require(library)
copy_libraries(manifest, args.destination)
main()

View File

@@ -0,0 +1,3 @@
#locally computed
sha256 4e43c59657b8da33b4bc503509a827cc3ea6cb66c446475c57776cf4467ba215 micropython-1.28.0.tar.xz
sha256 c7273a4675e28b40547b4814bf68da41954632ebbc38b3fff69f22d69850f690 LICENSE

View File

@@ -0,0 +1,81 @@
################################################################################
#
# micropython
#
################################################################################
MICROPYTHON_VERSION = 1.28.0
MICROPYTHON_SITE = https://micropython.org/resources/source
MICROPYTHON_SOURCE = micropython-$(MICROPYTHON_VERSION).tar.xz
# Micropython has a lot of code copied from other projects, and also a number
# of submodules for various libs. However, we don't even clone the submodules,
# and most of the copied code is not used in the unix build.
MICROPYTHON_LICENSE = MIT, BSD-1-Clause, BSD-3-Clause, Zlib
MICROPYTHON_LICENSE_FILES = LICENSE
MICROPYTHON_DEPENDENCIES = host-python3
MICROPYTHON_CPE_ID_VENDOR = micropython
# 0004-py-objarray-fix-use-after-free-if-extending-a-bytearray-from-itself.patch
MICROPYTHON_IGNORE_CVES += CVE-2024-8947
# Use fallback implementation for exception handling on architectures that don't
# have explicit support.
ifeq ($(BR2_i386)$(BR2_x86_64)$(BR2_arm)$(BR2_armeb),)
MICROPYTHON_CFLAGS += -DMICROPY_GCREGS_SETJMP=1
endif
# xtensa has problems with nlr_push, use setjmp based implementation instead
ifeq ($(BR2_xtensa),y)
MICROPYTHON_CFLAGS += -DMICROPY_NLR_SETJMP=1
endif
# When building from a tarball we don't have some of the dependencies that are in
# the git repository as submodules
MICROPYTHON_MAKE_OPTS += \
MICROPY_PY_BTREE=0 \
MICROPY_PY_USSL=0 \
CROSS_COMPILE=$(TARGET_CROSS) \
CFLAGS_EXTRA="$(MICROPYTHON_CFLAGS)" \
LDFLAGS_EXTRA="$(TARGET_LDFLAGS)" \
CWARN=
# Support libffi in MicroPython itself; separate from unix-ffi libraries
ifeq ($(BR2_PACKAGE_LIBFFI),y)
MICROPYTHON_DEPENDENCIES += host-pkgconf libffi
MICROPYTHON_MAKE_OPTS += MICROPY_PY_FFI=1
else
MICROPYTHON_MAKE_OPTS += MICROPY_PY_FFI=0
endif
define MICROPYTHON_BUILD_CMDS
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/mpy-cross
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/ports/unix \
$(MICROPYTHON_MAKE_OPTS)
endef
define MICROPYTHON_INSTALL_TARGET_CMDS
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)/ports/unix \
$(MICROPYTHON_MAKE_OPTS) \
DESTDIR=$(TARGET_DIR) \
PREFIX=/usr \
install
endef
ifeq ($(BR2_PACKAGE_MICROPYTHON_LIB),y)
define MICROPYTHON_COLLECT_LIBS
$(EXTRA_ENV) PYTHONPATH=$(@D)/tools \
package/micropython/collect_micropython_lib.py \
$(@D) $(@D)/.built_pylib \
$(if $(BR2_PACKAGE_MICROPYTHON_LIB_UNIXFFI),--ffi,--no-ffi)
endef
define MICROPYTHON_INSTALL_LIBS
$(INSTALL) -d -m 0755 $(TARGET_DIR)/usr/lib/micropython
cp -a $(@D)/.built_pylib/* $(TARGET_DIR)/usr/lib/micropython
endef
MICROPYTHON_POST_BUILD_HOOKS += MICROPYTHON_COLLECT_LIBS
MICROPYTHON_POST_INSTALL_TARGET_HOOKS += MICROPYTHON_INSTALL_LIBS
endif
$(eval $(generic-package))