Skip to content

Commit 763b1ba

Browse files
committed
onieprom: Create proper package
1 parent d419307 commit 763b1ba

File tree

11 files changed

+435
-42
lines changed

11 files changed

+435
-42
lines changed

board/common/post-image.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
# Only for regular builds, not bootloader-only builds
44
if [ "$BR2_TARGET_ROOTFS_SQUASHFS" = "y" ]; then
5-
cp "$BR2_EXTERNAL_INFIX_PATH/board/common/rootfs/usr/bin/onieprom" "$BINARIES_DIR/"
6-
75
# Quick intro for beginners, with links to more information
86
cp "$BR2_EXTERNAL_INFIX_PATH/board/common/README.txt" "$BINARIES_DIR/"
97
fi

board/common/rootfs/usr/libexec/infix/init.d/00-probe

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#!/usr/bin/env python3
22

3-
import importlib.machinery
43
import json
4+
import onieprom
55
import os
66
import shutil
77
import struct
88
import subprocess
99
import sys
1010

11-
onieprom = importlib.machinery.SourceFileLoader("onieprom", "/bin/onieprom").load_module()
1211
SYSTEM_JSON = "/run/system.json"
1312
KKIT_IANA_PEM = 61046
1413

package/Config.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ source "$BR2_EXTERNAL_INFIX_PATH/package/lowdown/Config.in"
2929
source "$BR2_EXTERNAL_INFIX_PATH/package/mcd/Config.in"
3030
source "$BR2_EXTERNAL_INFIX_PATH/package/mdns-alias/Config.in"
3131
source "$BR2_EXTERNAL_INFIX_PATH/package/netbrowse/Config.in"
32+
source "$BR2_EXTERNAL_INFIX_PATH/package/onieprom/Config.in"
3233
source "$BR2_EXTERNAL_INFIX_PATH/package/podman/Config.in"
3334
source "$BR2_EXTERNAL_INFIX_PATH/package/python-libyang/Config.in"
3435
source "$BR2_EXTERNAL_INFIX_PATH/package/python-statd/Config.in"

package/onieprom/Config.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
menuconfig BR2_PACKAGE_ONIEPROM
2+
bool "onieprom"
3+
default y
4+
select BR2_PACKAGE_HOST_PYTHON3
5+
select BR2_PACKAGE_DBUS_PYTHON
6+
help
7+
ONIE EEPROM parser/generator
8+
9+
config BR2_PACKAGE_ONIEPROM_INSTALL_IMAGES
10+
bool "install onieprom in images"
11+
depends on BR2_PACKAGE_ONIEPROM
12+
default y
13+
help
14+
Install the onieprom script in the images direcory. Useful
15+
when the release is destined for someone who will have to
16+
create ONIE EEPROM binaries for deployment during
17+
manufacturing.

package/onieprom/onieprom

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
PYTHONPATH=$(readlink -f $(dirname $0)/..) \
4+
exec python3 -m onieprom "$@"

package/onieprom/onieprom.mk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ONIEPROM_VERSION = 1.0
2+
ONIEPROM_SITE_METHOD = local
3+
ONIEPROM_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/onieprom
4+
ONIEPROM_LICENSE = GPLv2
5+
ONIEPROM_LICENSE_FILES = COPYING
6+
ONIEPROM_DEPENDENCIES = host-python3 python3 host-python-poetry-core
7+
ONIEPROM_SETUP_TYPE = pep517 # poetry
8+
ONIEPROM_INSTALL_IMAGES = $(if $(BR2_PACKAGE_ONIEPROM_INSTALL_IMAGES),YES,NO)
9+
10+
define ONIEPROM_INSTALL_IMAGES_CMDS
11+
@cp -a $(@D)/onieprom $(BINARIES_DIR)/onieprom
12+
@cp $(ONIEPROM_PKGDIR)/onieprom $(BINARIES_DIR)/onieprom/
13+
endef
14+
15+
$(eval $(python-package))

src/onieprom/COPYING

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

src/onieprom/onieprom/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
from .tlv import into_tlv, from_tlv

src/onieprom/onieprom/__main__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def main():
2+
import argparse
3+
import json
4+
import os
5+
import sys
6+
7+
parser = argparse.ArgumentParser(prog='onieprom')
8+
9+
parser.add_argument("infile", nargs="?", default=sys.stdin, type=argparse.FileType("rb", 0))
10+
parser.add_argument("outfile", nargs="?", default=sys.stdout, type=argparse.FileType("wb"))
11+
12+
parser.add_argument("-e", "--encode", default=False, action="store_true",
13+
help="Encode JSON input to binary output")
14+
15+
parser.add_argument("-d", "--decode", default=False, action="store_true",
16+
help="Decode binary input to JSON output")
17+
18+
args = parser.parse_args()
19+
20+
if (not args.encode) and (not args.decode):
21+
c = args.infile.read(1)
22+
args.infile.seek(0, 0)
23+
24+
if c == b"{":
25+
args.encode = True
26+
elif c == b"T":
27+
args.decode = True
28+
else:
29+
sys.stderr.write("Neither encode nor decode specified, and could not infer operation from input")
30+
sys.exit(1)
31+
32+
if args.encode:
33+
args.outfile.buffer.write(into_tlv(json.load(args.infile)))
34+
else:
35+
args.outfile.write(json.dumps(from_tlv(args.infile)))
36+
37+
if __name__ == "__main__":
38+
main()

board/common/rootfs/usr/bin/onieprom renamed to src/onieprom/onieprom/tlv.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
import binascii
42
import struct
53

@@ -180,39 +178,3 @@ def unpack_vendor(ext):
180178
d[info["name"]] = unpack(v)
181179

182180
return d
183-
184-
if __name__ == "__main__":
185-
import argparse
186-
import json
187-
import os
188-
import sys
189-
190-
parser = argparse.ArgumentParser(prog='onieprom')
191-
192-
parser.add_argument("infile", nargs="?", default=sys.stdin, type=argparse.FileType("rb", 0))
193-
parser.add_argument("outfile", nargs="?", default=sys.stdout, type=argparse.FileType("wb"))
194-
195-
parser.add_argument("-e", "--encode", default=False, action="store_true",
196-
help="Encode JSON input to binary output")
197-
198-
parser.add_argument("-d", "--decode", default=False, action="store_true",
199-
help="Decode binary input to JSON output")
200-
201-
args = parser.parse_args()
202-
203-
if (not args.encode) and (not args.decode):
204-
c = args.infile.read(1)
205-
args.infile.seek(0, 0)
206-
207-
if c == b"{":
208-
args.encode = True
209-
elif c == b"T":
210-
args.decode = True
211-
else:
212-
sys.stderr.write("Neither encode nor decode specified, and could not infer operation from input")
213-
sys.exit(1)
214-
215-
if args.encode:
216-
args.outfile.buffer.write(into_tlv(json.load(args.infile)))
217-
else:
218-
args.outfile.write(json.dumps(from_tlv(args.infile)))

0 commit comments

Comments
 (0)